Index: panels/layouts/twocol_stacked.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/layouts/twocol_stacked.inc,v
retrieving revision 1.5.6.6
diff -u -r1.5.6.6 twocol_stacked.inc
--- panels/layouts/twocol_stacked.inc	17 Dec 2007 22:09:19 -0000	1.5.6.6
+++ panels/layouts/twocol_stacked.inc	30 Apr 2008 10:19:20 -0000
@@ -10,8 +10,14 @@
     'title' => t('Two column stacked'),
     'icon' => 'layouts/twocol_stacked.png',
     'theme' => 'panels_twocol_stacked',
+    'theme arguments' => array('id', 'content'), 
     'css' => 'layouts/twocol_stacked.css',
-    'panels' => array('top' => t('Top'), 'left' => t('Left side'), 'right' => t('Right side'), 'bottom' => t('Bottom')),
+    'panels' => array(
+      'top' => t('Top'),
+      'left' => t('Left side'),
+      'right' => t('Right side'),
+      'bottom' => t('Bottom')
+    ),
   );
 
   return $items;
Index: panels/layouts/twocol.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/layouts/twocol.inc,v
retrieving revision 1.6.6.5
diff -u -r1.6.6.5 twocol.inc
--- panels/layouts/twocol.inc	17 Dec 2007 22:09:19 -0000	1.6.6.5
+++ panels/layouts/twocol.inc	30 Apr 2008 10:19:20 -0000
@@ -9,8 +9,12 @@
     'title' => t('Two column'),
     'icon' => 'layouts/twocol.png',
     'theme' => 'panels_twocol',
+    'theme arguments' => array('id', 'content'), 
     'css' => 'layouts/twocol.css',
-    'panels' => array('left' => t('Left side'), 'right' => t('Right side')),
+    'panels' => array(
+      'left' => t('Left side'),
+      'right' => t('Right side')
+    ),
   );
 
   return $items;
Index: panels/layouts/onecol.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/layouts/Attic/onecol.inc,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 onecol.inc
--- panels/layouts/onecol.inc	17 Dec 2007 22:09:19 -0000	1.1.2.4
+++ panels/layouts/onecol.inc	30 Apr 2008 10:19:20 -0000
@@ -9,6 +9,7 @@
     'title' => t('Single column'),
     'icon' => 'layouts/onecol.png',
     'theme' => 'panels_onecol',
+    'theme arguments' => array('id', 'content'), 
     'css' => 'layouts/onecol.css',
     'panels' => array('middle' => t('Middle column')),
   );
Index: panels/layouts/threecol_33_34_33_stacked.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/layouts/threecol_33_34_33_stacked.inc,v
retrieving revision 1.5.6.6
diff -u -r1.5.6.6 threecol_33_34_33_stacked.inc
--- panels/layouts/threecol_33_34_33_stacked.inc	17 Dec 2007 22:09:19 -0000	1.5.6.6
+++ panels/layouts/threecol_33_34_33_stacked.inc	30 Apr 2008 10:19:20 -0000
@@ -10,8 +10,15 @@
     'title' => t('Three column 33/34/33 stacked'),
     'icon' => 'layouts/threecol_33_34_33_stacked.png',
     'theme' => 'panels_threecol_33_34_33_stacked',
+    'theme arguments' => array('id', 'content'), 
     'css' => 'layouts/threecol_33_34_33_stacked.css',
-    'panels' => array('top' => t('Top'), 'left' => t('Left side'), 'middle' => t('Middle column'), 'right' => t('Right side'), 'bottom' => t('Bottom')),
+    'panels' => array(
+      'top' => t('Top'),
+      'left' => t('Left side'),
+      'middle' => t('Middle column'),
+      'right' => t('Right side'),
+      'bottom' => t('Bottom')
+    ),
   );
 
   return $items;
Index: panels/layouts/twocol_bricks.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/layouts/Attic/twocol_bricks.inc,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 twocol_bricks.inc
--- panels/layouts/twocol_bricks.inc	17 Dec 2007 22:09:19 -0000	1.1.2.2
+++ panels/layouts/twocol_bricks.inc	30 Apr 2008 10:19:20 -0000
@@ -15,6 +15,7 @@
     'title' => t('Two column bricks'),
     'icon' => 'layouts/twocol_bricks.png',
     'theme' => 'panels_twocol_bricks',
+    'theme arguments' => array('id', 'content'), 
     'css' => 'layouts/twocol_bricks.css',
     'panels' => array(
       'top' => t('Top'),
Index: panels/layouts/threecol_25_50_25.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/layouts/threecol_25_50_25.inc,v
retrieving revision 1.4.6.5
diff -u -r1.4.6.5 threecol_25_50_25.inc
--- panels/layouts/threecol_25_50_25.inc	17 Dec 2007 22:09:19 -0000	1.4.6.5
+++ panels/layouts/threecol_25_50_25.inc	30 Apr 2008 10:19:20 -0000
@@ -8,8 +8,13 @@
     'title' => t('Three column 25/50/25'),
     'icon' => 'layouts/threecol_25_50_25.png',
     'theme' => 'panels_threecol_25_50_25',
+    'theme arguments' => array('id', 'content'),
     'css' => 'layouts/threecol_25_50_25.css',
-    'panels' => array('left' => t('Left side'), 'middle' => t('Middle column'), 'right' => t('Right side')),
+    'panels' => array(
+      'left' => t('Left side'),
+      'middle' => t('Middle column'),
+      'right' => t('Right side')
+    ),
   );
 
   return $items;
Index: panels/layouts/threecol_33_34_33.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/layouts/threecol_33_34_33.inc,v
retrieving revision 1.5.6.5
diff -u -r1.5.6.5 threecol_33_34_33.inc
--- panels/layouts/threecol_33_34_33.inc	17 Dec 2007 22:09:19 -0000	1.5.6.5
+++ panels/layouts/threecol_33_34_33.inc	30 Apr 2008 10:19:20 -0000
@@ -9,8 +9,13 @@
     'title' => t('Three column 33/34/33'),
     'icon' => 'layouts/threecol_33_34_33.png',
     'theme' => 'panels_threecol_33_34_33',
+    'theme arguments' => array('id', 'content'), 
     'css' => 'layouts/threecol_33_34_33.css',
-    'panels' => array('left' => t('Left side'), 'middle' => t('Middle column'), 'right' => t('Right side')),
+    'panels' => array(
+      'left' => t('Left side'),
+      'middle' => t('Middle column'),
+      'right' => t('Right side')
+     ),
   );
 
   return $items;
Index: panels/layouts/flexible.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/layouts/Attic/flexible.inc,v
retrieving revision 1.1.2.10
diff -u -r1.1.2.10 flexible.inc
--- panels/layouts/flexible.inc	18 Mar 2008 02:49:12 -0000	1.1.2.10
+++ panels/layouts/flexible.inc	30 Apr 2008 10:19:20 -0000
@@ -8,6 +8,7 @@
     'title' => t('Flexible'),
     'icon' => 'layouts/flexible.png',
     'theme' => 'panels_flexible',
+    'theme arguments' => array('id', 'content', 'settings'), 
     'css' => 'layouts/flexible.css',
     'settings form' => 'panels_flexible_settings_form',
     'settings submit' => 'panels_flexible_settings_submit',
Index: panels/layouts/threecol_25_50_25_stacked.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/layouts/threecol_25_50_25_stacked.inc,v
retrieving revision 1.5.6.6
diff -u -r1.5.6.6 threecol_25_50_25_stacked.inc
--- panels/layouts/threecol_25_50_25_stacked.inc	17 Dec 2007 22:09:19 -0000	1.5.6.6
+++ panels/layouts/threecol_25_50_25_stacked.inc	30 Apr 2008 10:19:20 -0000
@@ -10,8 +10,15 @@
     'title' => t('Three column 25/50/25 stacked'),
     'icon' => 'layouts/threecol_25_50_25_stacked.png',
     'theme' => 'panels_threecol_25_50_25_stacked',
+    'theme arguments' => array('id', 'content'),
     'css' => 'layouts/threecol_25_50_25_stacked.css',
-    'panels' => array('top' => t('Top'), 'left' => t('Left side'), 'middle' => t('Middle column'), 'right' => t('Right side'), 'bottom' => t('Bottom')),
+    'panels' => array(
+      'top' => t('Top'),
+      'left' => t('Left side'),
+      'middle' => t('Middle column'),
+      'right' => t('Right side'),
+      'bottom' => t('Bottom')
+    ),
   );
 
   return $items;
Index: panels/panels.info
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels.info,v
retrieving revision 1.2.4.3
diff -u -r1.2.4.3 panels.info
--- panels/panels.info	18 Jun 2007 23:17:13 -0000	1.2.4.3
+++ panels/panels.info	30 Apr 2008 10:19:17 -0000
@@ -1,5 +1,6 @@
 ; $Id: panels.info,v 1.2.4.3 2007/06/18 23:17:13 dww Exp $
 name = Panels
 description = Core Panels display functions; provides no external UI, at least one other module (such as Panel pages) should be enabled.
-package = "Panels"
+package = Panels
+core = 6.x
 
Index: panels/panels.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels.module,v
retrieving revision 1.10.4.83
diff -u -r1.10.4.83 panels.module
--- panels/panels.module	18 Mar 2008 01:30:25 -0000	1.10.4.83
+++ panels/panels.module	30 Apr 2008 10:19:19 -0000
@@ -20,128 +20,238 @@
 }
 
 /**
- * Returns the API version of Panels. This didn't exist in 1.
- *
- * @return An array with the major and minor versions
+ * Implementation of hook_theme
  */
-function panels_api_version() {
-  return array(2, 0);
+function panels_theme() {
+  $theme = array();
+  $theme['panels_layout_link'] = array(
+    'arguments' => array('title', 'id', 'image', 'link'),
+  );
+  $theme['panels_layout_icon'] = array(
+    'arguments' => array('id', 'image', 'title' => NULL),
+  );
+  $theme['panels_imagebutton'] = array(
+    'arguments' => array('element'),
+  );
+  $theme['panels_edit_display_form'] = array(
+    'arguments' => array('form'),
+    'file' => 'includes/display_edit.inc',
+  );
+  $theme['panels_edit_layout_form_choose'] = array(
+    'arguments' => array('form'),
+    'file' => 'includes/display_edit.inc',
+  );
+/*  $theme['panels_edit_layout_form_change'] = array(
+    'arguments' => array('form'),
+    'file' => 'includes/display_edit.inc',
+  );*/
+  $theme['panels_pane'] = array(
+    'arguments' => array('content', 'pane', 'display'),
+    'file' => 'includes/theme.inc',
+  );
+  $theme['panels_common_content_list'] = array(
+    'arguments' => array('display'),
+    'file' => 'includes/theme.inc',
+  );
+  $theme['panels_common_context_list'] = array(
+    'arguments' => array('object'),
+    'file' => 'includes/theme.inc',
+  );
+  $theme['panels_common_context_item_form'] = array(
+    'arguments' => array('form'),
+    'file' => 'includes/theme.inc',
+  );
+  $theme['panels_common_content_item_row'] = array(
+    'arguments' => array('type', 'form', 'position', 'count', 'with_tr' => TRUE),
+    'file' => 'includes/theme.inc',
+  );
+  $theme['panels_dnd'] = array(
+    'arguments' => array('content'),
+    'file' => 'includes/theme.inc',
+  );
+  $theme['panels_panel_dnd'] = array(
+    'arguments' => array('content', 'area', 'label', 'footer'),
+    'file' => 'includes/theme.inc',
+  );
+  $theme['panels_pane_dnd'] = array(
+    'arguments' => array('block', 'id', 'label', 'left_buttons' => NULL, 'buttons' => NULL),
+    'file' => 'includes/theme.inc',
+  );
+  $theme['panels_pane_collapsible'] = array(
+    'arguments' => array('block'),
+    'file' => 'includes/theme.inc',
+  );
+  $theme['panels_hidden'] = array(
+    'arguments' => array(),
+    'file' => 'includes/theme.inc',
+  );
+  panels_load_include('plugins');
+
+  $layouts = panels_get_layouts();
+  foreach ($layouts as $name => $data) {
+    $theme[$data['theme']] = array(
+      'arguments' => $data['theme arguments'],
+      'file' => "layouts/$name.inc",
+  );
+  }
+
+  $styles = panels_get_styles();
+  foreach ($styles as $name => $data) {
+    $theme[$data['theme']] = array(
+      'arguments' => $data['theme arguments'],
+      'file' => "styles/$name.inc",
+  );
+  }
+
+  return $theme;
 }
 
 /**
  * Implementation of hook_menu
  */
-function panels_menu($may_cache) {
-  if ($may_cache) {
-    $items[] = array(
-      'path' => 'admin/panels',
-      'title' => t('Panels'),
-      'access' => user_access('access administration pages'),
-      'callback' => 'system_admin_menu_block_page',
-      'description' => t('Administer items related to the Panels module.'),
-    );
-    $items[] = array(
-      'path' => 'panels/node/autocomplete',
-      'title' => t('Autocomplete node'),
-      'callback' => 'panels_node_autocomplete',
-      'access' => user_access('access content'),
-      'type' => MENU_CALLBACK
-    );
-    $items[] = array(
-      'path' => 'panels/ajax',
-      'title' => t('ajax'),
-      'callback' => 'panels_ajax_passthru',
-      'callback arguments' => array('panels_ajax'),
-      'access' => user_access('access content'),
-      'type' => MENU_CALLBACK
-    );
-    $items[] = array(
-      'path' => 'panels/common/ajax',
-      'title' => t('ajax'),
-      'callback' => 'panels_ajax_passthru',
-      'callback arguments' => array('panels_common_ajax'),
-      'access' => user_access('access content'),
-      'type' => MENU_CALLBACK
-    );
-    $items[] = array(
-      'path' => 'panels/ajax/add-content',
-      'title' => t('ajax'),
-      'callback' => 'panels_ajax_passthru',
-      'callback arguments' => array('panels_ajax_add_content'),
-      'access' => user_access('access content'),
-      'type' => MENU_CALLBACK
-    );
-    $items[] = array(
-      'path' => 'panels/ajax/add-config',
-      'title' => t('ajax'),
-      'callback' => 'panels_ajax_passthru',
-      'callback arguments' => array('panels_ajax_add_config'),
-      'access' => user_access('access content'),
-      'type' => MENU_CALLBACK
-    );
-    $items[] = array(
-      'path' => 'panels/ajax/configure',
-      'title' => t('ajax'),
-      'callback' => 'panels_ajax_passthru',
-      'callback arguments' => array('panels_ajax_configure'),
-      'access' => user_access('access content'),
-      'type' => MENU_CALLBACK
-    );
-    $items[] = array(
-      'path' => 'panels/ajax/cache',
-      'title' => t('ajax'),
-      'callback' => 'panels_ajax_passthru',
-      'callback arguments' => array('panels_ajax_cache'),
-      'access' => user_access('access content'),
-      'type' => MENU_CALLBACK
-    );
-    $items[] = array(
-      'path' => 'panels/ajax/cache-settings',
-      'title' => t('ajax'),
-      'callback' => 'panels_ajax_passthru',
-      'callback arguments' => array('panels_ajax_cache_settings'),
-      'access' => user_access('access content'),
-      'type' => MENU_CALLBACK
-    );
-    $items[] = array(
-      'path' => 'panels/ajax/panel_settings',
-      'title' => t('ajax'),
-      'callback' => 'panels_ajax_passthru',
-      'callback arguments' => array('panels_panel_settings_ajax'),
-      'access' => user_access('access content'),
-      'type' => MENU_CALLBACK
-    );
-  }
-  else {
-    drupal_add_css(panels_get_path('css/panels.css'));
-    drupal_add_js(panels_get_path('js/panels.js'));
-  }
-
+function panels_menu() {
+  $items = array();
+  $items['admin/panels'] = array(
+    'title' => t('Panels'),
+    'access arguments' => array('access administration pages'),
+    'page callback' => 'system_admin_menu_block_page',
+    'file' => 'system.admin.inc',
+    'file path' => drupal_get_path('module', 'system'),
+    'description' => t('Administer items related to the Panels module.'),
+  );
+  $items['panels/node/autocomplete'] = array(
+    'title' => t('Autocomplete node'),
+    'page callback' => 'panels_node_autocomplete',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    'file' => 'panels.callbacks.inc',
+  );
+  $items['panels/ajax'] = array(
+    'title' => t('ajax'),
+    'page callback' => 'panels_ajax_passthru',
+    'page arguments' => array('panels_ajax'),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    'file' => 'panels.callbacks.inc',
+  );
+  $items['panels/common/ajax'] = array(
+    'title' => t('ajax'),
+    'page callback' => 'panels_ajax_passthru',
+    'page arguments' => array('panels_common_ajax'),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    'file' => 'panels.callbacks.inc',
+  );
+  $items['panels/ajax/add-content'] = array(
+    'title' => t('ajax'),
+    'page callback' => 'panels_ajax_passthru',
+    'page arguments' => array('panels_ajax_add_content'),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    'file' => 'panels.callbacks.inc',
+  );
+  $items['panels/ajax/add-config'] = array(
+    'title' => t('ajax'),
+    'page callback' => 'panels_ajax_passthru',
+    'page arguments' => array('panels_ajax_add_config'),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    'file' => 'panels.callbacks.inc',
+  );
+  $items['panels/ajax/configure'] = array(
+    'title' => t('ajax'),
+    'page callback' => 'panels_ajax_passthru',
+    'page arguments' => array('panels_ajax_configure'),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    'file' => 'panels.callbacks.inc',
+  );
+  $items['panels/ajax/cache'] = array(
+    'title' => t('ajax'),
+    'page callback' => 'panels_ajax_passthru',
+    'page arguments' => array('panels_ajax_cache'),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    'file' => 'panels.callbacks.inc',
+  );
+  $items['panels/ajax/cache-settings'] = array(
+    'title' => t('ajax'),
+    'page callback' => 'panels_ajax_passthru',
+    'page arguments' => array('panels_ajax_cache_settings'),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    'file' => 'panels.callbacks.inc',
+  );
+  $items['panels/ajax/panel_settings'] = array(
+    'title' => t('ajax'),
+    'page callback' => 'panels_ajax_passthru',
+    'page arguments' => array('panels_panel_settings_ajax'),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+    'file' => 'panels.callbacks.inc',
+  );
   return $items;
 }
 
 /**
- * Load a panels include file.
+ * Implementation of hook_perm
  */
-function panels_load_include($include, $path = 'includes/') {
-  require_once './' . panels_get_path("$path$include.inc");
+function panels_perm() {
+  return array('view all panes', 'view pane admin links', 'administer pane visibility', 'administer advanced pane settings', 'use panels caching features');
 }
 
 /**
- * Helper function for our AJAX stuff to call through to the right location
+ * Implementation of hook_init().
  */
-function panels_ajax_passthru() {
-  $args = func_get_args();
-  $callback = array_shift($args);
+function panels_init() {
+  menu_rebuild();
+  drupal_add_css(panels_get_path('css/panels.css'));
+  drupal_add_js(panels_get_path('js/panels.js'));  
+}
 
-  panels_load_include('plugins');
-  if (arg(1) == 'common') {
-    panels_load_include('common');
-  }
-  else {
-    panels_load_include('display_edit');
+/**
+ * Implementation of hook_cron().
+ */
+function panels_cron() {
+  panels_common_cache_cron();
+}
+
+/**
+ * Returns the API version of Panels. This didn't exist in 1.
+ *
+ * @return array
+ *   (optional) An array with the major and minor versions
+ */
+function panels_api_version() {
+  return array(2, 0);
+}
+
+/**
+ * Panels path helper function
+ * 
+ * @param $file
+ *   File to get the path for, including its path relative to the directory of
+ *   the module defined by $module (e.g. 'includes/plugins.inc').
+ * @param $base_path
+ *   (optional) Flag to prepend the base_path(). Defaults to FALSE.
+ * @param $module
+ *   (optional) Module directory in which the file is in. Defaults to 'panels'.
+ *
+ * @return string
+ *   The path to the requested file.
+ */
+function panels_get_path($file, $base_path = FALSE, $module = 'panels') {
+  if ($base_path) {
+    $output = base_path();
   }
-  return call_user_func_array($callback, $args);
+  return $output . drupal_get_path('module', $module) . '/' . $file;
+}
+
+/**
+ * Load a panels include file.
+ */
+function panels_load_include($include, $path = 'includes/') {
+  require_once './' . panels_get_path("$path$include.inc");
 }
 
 /**
@@ -173,11 +283,10 @@
   exit;
 }
 
-
 /**
  * Handle a form for AJAX in a manner that happens to be basically the
  * opposite of the normal flow; if the form hasn't been processed,
- * just render it and exit; if it has been submitted successfuly, however,
+ * just render it and exit; if it has been submitted successfully, however,
  * then we return whatever the submit function returned and do our
  * next step accordingly.
  *
@@ -188,7 +297,7 @@
  * @param $url
  *   The next URL to go to; may be NULL.
  * @param ...
- *   Any arguments that go to the form.
+ *   (optional) Any additional arguments that go to the form.
  */
 function panels_ajax_form($form_id, $title, $url) {
   $args = func_get_args();
@@ -199,7 +308,7 @@
   $form = call_user_func_array('drupal_retrieve_form', $args);
   $form['#redirect'] = FALSE;
 
-  $result = drupal_process_form($form_id, $form);
+  $result = drupal_process_form($form_id, $form, $form_state);
   if (isset($result)) {
     return $result;
   }
@@ -210,34 +319,23 @@
   panels_ajax_render($output, $title, $url);
 }
 
-/**
- * panels path helper function
- */
-function panels_get_path($file, $base_path = false, $module = 'panels') {
-  if ($base_path) {
-    $output = base_path();
-  }
-  return $output . drupal_get_path('module', $module) . '/' . $file;
-}
-
-/**
- * Implementation of hook_perm
- */
-function panels_perm() {
-  return array('view all panes', 'view pane admin links', 'administer pane visibility', 'administer advanced pane settings', 'use panels caching features');
-}
-
 // ---------------------------------------------------------------------------
 // panels custom image button
 
 /**
+ * Implementation of hook_elements
+ * 
  * Custom form element to do our nice images.
  */
 function panels_elements() {
-  $type['panels_imagebutton'] = array('#input' => TRUE, '#button_type' => 'submit',);
+  $type['panels_imagebutton'] = array('#input' => TRUE, '#button_type' => 'submit');
   return $type;
 }
 
+function panels_imagebutton_value() {
+  // null function guarantees default_value doesn't get moved to #value.
+}
+
 /**
  * Theme our image button.
  */
@@ -254,17 +352,13 @@
     "/>\n";
 }
 
-function panels_imagebutton_value() {
-  // null function guarantees default_value doesn't get moved to #value.
-}
-
 /**
  * Add a single button to a form.
  */
 function panels_add_button($image, $name, $text, $class, $id = NULL) {
   return array(
     '#type' => 'panels_imagebutton',
-    '#image' => panels_get_path('images/' . $image),
+    '#image' => panels_get_path("images/$image"),
     '#title' => $text,
     '#default_value' => $name,
     '#class' => $class,
@@ -330,7 +424,7 @@
 }
 
 /**
- * Save the edited display into the cache.
+ * Save the edited object into the cache.
  */
 function panels_common_cache_set($obj, $did, $cache) {
   panels_common_cache_clear($obj, $did);
@@ -338,7 +432,7 @@
 }
 
 /**
- * Clear a display from the cache; used if the editing is aborted.
+ * Clear a object from the cache; used if the editing is aborted.
  */
 function panels_common_cache_clear($obj, $did) {
   db_query("DELETE FROM {panels_object_cache} WHERE sid = '%s' AND obj = '%s' AND did = %d", session_id(), $obj, $did);
@@ -347,7 +441,7 @@
 /**
  * Clean up old caches
  */
-function panels_cron() {
+function panels_common_cache_cron() {
   // delete anything 7 days old or more.
   db_query("DELETE FROM {panels_object_cache} WHERE timestamp < %d", time() - (86400 * 7));
 }
@@ -382,6 +476,7 @@
 function panels_edit($display, $destination = NULL, $content_types = NULL) {
   panels_load_include('display_edit');
   panels_load_include('plugins');
+  panels_load_include('common'); // ?
   return _panels_edit($display, $destination, $content_types);
 }
 
@@ -390,7 +485,7 @@
  *
  * TODO: Doc this. Important.
  */
-function panels_edit_layout($display, $finish, $destination = NULL) {
+function panels_edit_layout(&$display, $finish, $destination = NULL) {
   panels_load_include('display_edit');
   panels_load_include('plugins');
   return _panels_edit_layout($display, $finish, $destination);
@@ -424,31 +519,36 @@
 }
 
 /**
- * Clean up a display and make sure it has some required information if
- * it doesn't already exist. Currently we wrequire a context, an incoming
- * content and a css_id.
+ * Clean up a display object and add some required information, if missing.
+ * 
+ * Currently a display object needs 'args', 'incoming content', 'context'
+ * and a 'css_id'.
+ * 
+ * @param &$display
+ *   The display object to be sanitized.
+ * @return
+ *   The sanitized display object.
  */
 function panels_sanitize_display(&$display) {
   if (!isset($display->args)) {
     $display->args = array();
   }
-
   if (!isset($display->incoming_content)) {
     $display->incoming_content = NULL;
   }
-
   if (!isset($display->context)) {
     $display->context = array();
   }
-
   if (!isset($display->css_id)) {
     $display->css_id = NULL;
   }
 }
 
-
 /**
- * Creates a new display, setting the ID to our magic new id.
+ * Create a new display, setting the ID to the magic id 'new'.
+ * 
+ * @return
+ *   The newly created display object.
  */
 function panels_new_display() {
   $display = new panels_display();
@@ -457,7 +557,12 @@
 }
 
 /**
- * Load a display from the database
+ * Load display objects from the database.
+ * 
+ * @param $dids
+ *   Array containing the IDs of the displays to be loaded.
+ * @return
+ *   Array containing the loaded display objects.
  */
 function panels_load_displays($dids) {
   $displays = array();
@@ -477,9 +582,9 @@
     }
 
     // unserialize important bits:
-    $display->layout_settings = empty($display->layout_settings) ? array() : unserialize($display->layout_settings);
-    $display->panel_settings = empty($display->panel_settings) ? array() : unserialize($display->panel_settings);
-    $display->cache = empty($display->cache) ? array() : unserialize($display->cache);
+    foreach (array('layout_settings', 'panel_settings', 'cache') as $value) { 
+      $display->$value = empty($display->$value) ? array() : unserialize($display->$value);
+    }
 
     $display->panels = $display->content = array();
 
@@ -500,7 +605,12 @@
 }
 
 /**
- * Load a single display.
+ * Load a single display object from the database.
+ * 
+ * @param $did
+ *   ID of the display to be loaded.
+ * @return
+ *   The loaded display object.
  */
 function panels_load_display($did) {
   $displays = panels_load_displays(array($did));
@@ -510,97 +620,121 @@
 }
 
 /**
- * Save a display.
+ * Save a new or updated display to the database.
+ * 
+ * @param &$display
+ *   The display object to be saved.
+ * @return
+ *   The did of the saved display object, or FALSE if an error occured.
  */
 function panels_save_display(&$display) {
-  if ($display->did && $display->did != 'new') {
-    if (empty($display->cache)) {
-      $display->cache = array();
-    }
+  // Make sure we don't mess up the original display object.
+  $d_temp = drupal_clone($display);
+  $d_temp->layout_settings = serialize($display->layout_settings);
+  $d_temp->panel_settings = serialize($display->panel_settings);
+  $d_temp->cache = empty($display->cache) ? serialize(array()) : serialize($display->cache);
 
-    db_query("UPDATE {panels_display} SET layout = '%s', layout_settings = '%s', panel_settings = '%s', cache = '%s' WHERE did = %d", $display->layout, serialize($display->layout_settings), serialize($display->panel_settings), serialize($display->cache), $display->did);
-    db_query("DELETE FROM {panels_pane} WHERE did = %d", $display->did);
+  if ($display->did && $display->did != 'new') {
+    $d_temp->did = (integer)($display->did);
+    $status = drupal_write_record('panels_display', $d_temp, array('did'));
   }
   else {
-    $display->did = db_next_id("{panels_display}_did");
-    db_query("INSERT INTO {panels_display} (did, layout, layout_settings, panel_settings, cache) VALUES (%d, '%s', '%s', '%s', '%s')", $display->did, $display->layout, serialize($display->layout_settings), serialize($display->panel_settings), serialize($display->cache));
+    $status = drupal_write_record('panels_display', $d_temp);
   }
 
-  // update all the panes
-  foreach ((array) $display->panels as $id => $panes) {
-    $position = 0;
-    $new_panes = array();
-    foreach ((array) $panes as $pid) {
-      $pane = $display->content[$pid];
-      $pane->position = $position++;
-      if (!is_numeric($pid)) {
-        unset($display->content[$pid]);
-        $pane->pid = db_next_id("{panels_pane}_pid");
-      }
-      if (empty($pane->cache)) {
-        $pane->cache = array();
+  switch ($status) {
+    case SAVED_NEW:
+      $display->did = db_last_insert_id('panels_display', 'did');
+    case SAVED_UPDATED:
+      db_query("DELETE FROM {panels_pane} WHERE did = %d", $display->did);
+    case TRUE:
+      // (Re)create all the panes.
+      foreach ((array) $display->panels as $id => $panes) {
+        $position = 0;
+        $new_panes = array();
+        foreach ((array) $panes as $pid) {
+          $pane = $display->content[$pid];
+          $pane->position = $position++;
+          if (!is_numeric($pid)) {
+            unset($display->content[$pid]);
+            // $pane->pid = db_next_id("{panels_pane}_pid");
+          }
+          if (empty($pane->cache)) {
+            $pane->cache = array();
+          }
+
+          db_query("INSERT INTO {panels_pane} (pid, did, panel, type, subtype, configuration, cache, access, position) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d)", $pane->pid, $display->did, $pane->panel, $pane->type, $pane->subtype, serialize($pane->configuration), serialize($pane->cache), !empty($pane->access) ? implode(', ', $pane->access) : '', $pane->position);
+          // and put it back so our pids and positions can be used
+              $display->content[$pane->pid] = $pane;
+          $new_panes[] = $pane->pid;
+        }
+        $display->panels[$id] = $new_panes;
       }
 
-      db_query("INSERT INTO {panels_pane} (pid, did, panel, type, subtype, configuration, cache, access, position) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d)", $pane->pid, $display->did, $pane->panel, $pane->type, $pane->subtype, serialize($pane->configuration), serialize($pane->cache), !empty($pane->access) ? implode(', ', $pane->access) : '', $pane->position);
-      // and put it back so our pids and positions can be used
-          $display->content[$pane->pid] = $pane;
-      $new_panes[] = $pane->pid;
+      // Clear any cached content for this display.
+      panels_load_include('plugins');
+      panels_clear_cached_content($display);  
     }
-    $display->panels[$id] = $new_panes;
-  }
 
-  // Clear any cached content for this display.
-  panels_load_include('plugins');
-  panels_clear_cached_content($display);
-
-  return $display; // to be nice, even tho we have a reference.
+  return $display->did;
 }
 
 /**
- * Delete a display
+ * Delete a display with all its panes.
+ * 
+ * @param $did
+ *   ID of a display.
+ * @return
+ *   A boolean value indicating whether the query was successful.
  */
-function panels_delete_display($display) {
-  if (is_object($display)) {
-    $did = $display->did;
+function panels_delete_display($did) {
+  if (is_object($did)) {
+    $did = $did->did;
   }
-  else {
-    $did = $display;
+  if ($success = db_query("DELETE FROM {panels_display} WHERE did = %d", $did)) {
+    db_query("DELETE FROM {panels_pane} WHERE did = %d", $did);
   }
-  db_query("DELETE FROM {panels_display} WHERE did = %d", $did);
-  db_query("DELETE FROM {panels_pane} WHERE did = %d", $did);
+  return $success == TRUE;
 }
 
 /**
  * Export a display into code
+ * 
+ * @param $display
+ *   The display object to be exported.
+ * @param $prefix
+ *   (optional).
+ * @return
+ *   PHP code to re-create the display object.
  */
 function panels_export_display($display, $prefix = '') {
   $output = '';
-  $output .= $prefix . '$display = new stdClass()' . ";\n";
-  $output .= $prefix . '$display->did = \'new\'' . ";\n";
-  $fields = array('name', 'layout', 'layout_settings', 'panel_settings');
+  $output .= $prefix . "\$display = new stdClass();\n";
+  $output .= $prefix . "\$display->did = 'new';\n";
+  $fields = array_diff(drupal_schema_fields_sql('panels_display'), array('did', 'cache'));
   foreach ($fields as $field) {
-    $output .= $prefix . '$display->' . $field . ' = ' . panels_var_export($display->$field, $prefix) . ";\n";
+    $output .= $prefix . "\$display->$field = " . panels_var_export($display->$field, $prefix) . ";\n";
   }
 
-  $output .= $prefix . '$display->content = array()' . ";\n";
-  $output .= $prefix . '$display->panels = array()' . ";\n";
+  $output .= $prefix . "\$display->content = array();\n";
+  $output .= $prefix . "\$display->panels = array();\n";
   $panels = array();
 
   $counter = 0;
   $counters = array();
   foreach ($display->content as $pane) {
     $id = 'new-' . ++$counter;
-    $output .= $prefix . '$pane = new stdClass()'  . ";\n";
-    $output .= $prefix . '  $pane->pid = \'' . $id . '\'' . ";\n";
+    $output .= $prefix . "\$pane = new stdClass();\n";
+    $output .= $prefix . "  \$pane->pid = '$id';\n";
     $fields = array('panel', 'type', 'subtype', 'access', 'configuration');
     foreach ($fields as $field) {
-      $output .= $prefix . '  $pane->' . $field . ' = ' . panels_var_export($pane->$field, "$prefix  ") . ";\n";
+      $output .= $prefix . "  \$pane->$field = " . panels_var_export($pane->$field, "$prefix  ") . ";\n";
     }
-    $output .= $prefix . '$display->content[\'' . $id . '\'] = $pane' . ";\n";
+    $output .= $prefix . "\$display->content['$id'] = $pane;\n";
     if (!isset($counters[$pane->panel])) {
       $counters[$pane->panel] = 0;
     }
-    $output .= $prefix . '$display->panels[\'' . $pane->panel . '\'][' . $counters[$pane->panel]++ .'] = \'' . $id . "';\n";
+    $output .= $prefix . "\$display->panels['$pane->panel']['" . $counters[$pane->panel]++ . "'] = '$id';\n";
   }
   return $output;
 }
@@ -855,9 +989,9 @@
  * @param $display
  *   A display object.
  * @param $panel
- *   The ID of the panel being rendered
+ *   The ID of the panel to be rendered
  * @param $panes
- *   An array of panes that are assigned to the panel that's being rendered.
+ *   An array of panes that are assigned to the panel to be rendered.
  * @return
  *   The rendered HTML for a panel.
  * @render
@@ -885,18 +1019,11 @@
 function panels_print_layout_link($id, $layout, $link) {
   drupal_add_css(panels_get_path('css/panels_admin.css'));
   $file = panels_get_path($layout['icon'], false, $layout['module']);
-  $image = l(theme('image', $file), $link, NULL, NULL, NULL, NULL, TRUE);
+  $image = l(theme('image', $file), $link,array('html' => true));
   $title = l($layout['title'], $link);
   return theme('panels_layout_link', $title, $id, $image, $link);
 }
 
-// @layout
-function panels_print_layout_icon($id, $layout, $title = NULL) {
-  drupal_add_css(panels_get_path('css/panels_admin.css'));
-  $file = panels_get_path($layout['icon'], false, $layout['module']);
-  return theme('panels_layout_icon', $id, theme('image', $file), $title);
-}
-
 /**
  * Theme the layout link image
  * @layout
@@ -909,6 +1036,13 @@
   return $output;
 }
 
+// @layout
+function panels_print_layout_icon($layout, $title = NULL) {
+  drupal_add_css(panels_get_path('css/panels_admin.css'));
+  $file = panels_get_path($layout['icon'], false, $layout['module']);
+  return theme('panels_layout_icon', $layout['name'], theme('image', $file), $title);
+}
+
 /**
  * Theme the layout icon image
  * @layout
@@ -921,96 +1055,4 @@
   }
   $output .= '</div>';
   return $output;
-}
-
-/**
- * Render a panel pane like a block.
- *
- * A panel pane can have the following fields:
- *
- * $pane->type -- the content type inside this pane
- * $pane->subtype -- The subtype, if applicable. If a view it will be the
- *   view name; if a node it will be the nid, etc.
- * $content->title -- The title of the content
- * $content->content -- The actual content
- * $content->links -- Any links associated with the content
- * $content->more -- An optional 'more' link (destination only)
- * $content->admin_links -- Administrative links associated with the content
- * $content->feeds -- Any feed icons or associated with the content
- * $content->subject -- A legacy setting for block compatibility
- * $content->module -- A legacy setting for block compatibility
- * $content->delta -- A legacy setting for block compatibility
- */
-function theme_panels_pane($content, $pane, $display) {
-  if (!empty($content->content)) {
-    $idstr = $classstr = '';
-    if (!empty($content->css_id)) {
-      $idstr = ' id="' . $content->css_id . '"';
-    }
-    if (!empty($content->css_class)) {
-      $classstr = ' ' . $content->css_class;
-    }
-
-    $output = "<div class=\"panel-pane$classstr\"$idstr>\n";
-    if (user_access('view pane admin links') && !empty($content->admin_links)) {
-      $output .= "<div class=\"admin-links panel-hide\">" . theme('links', $content->admin_links) . "</div>\n";
-    }
-    if (!empty($content->title)) {
-      $output .= "<h2 class=\"title\">$content->title</h2>\n";
-    }
-
-    if (!empty($content->feeds)) {
-      $output .= "<div class=\"feed\">" . implode(' ', $content->feeds) . "</div>\n";
-    }
-
-    $output .= "<div class=\"content\">$content->content</div>\n";
-
-    if (!empty($content->links)) {
-      $output .= "<div class=\"links\">" . theme('links', $content->links) . "</div>\n";
-    }
-
-
-    if (!empty($content->more)) {
-      if (empty($content->more['title'])) {
-        $content->more['title'] = t('more');
-      }
-      $output .= "<div class=\"more-link\">" . l($content->more['title'], $content->more['href']) . "</div>\n";
-    }
-
-    $output .= "</div>\n";
-    return $output;
-  }
-}
-
-/**
- * Helper function for autocompletion of node titles.
- * This is mostly stolen from clipper.
- */
-function panels_node_autocomplete($string) {
-  // TODO: Compare this to the nodequeue version, see which is better.
-  // TODO: The nodequeue version is totally better. Steal it.
-  if ($string != '') { // if there are node_types passed, we'll use those in a MySQL IN query.
-    $preg_matches = array();
-    $match = preg_match('/\[nid: (\d+)\]/', $string, $preg_matches);
-    if (!$match) {
-      $match = preg_match('/^nid: (\d+)/', $string, $preg_matches);
-    }
-    if ($match) {
-      $arg = $preg_matches[1];
-      $where = "n.nid = %d";
-    }
-    else {
-      $arg = $string;
-      $where = "LOWER(title) LIKE LOWER('%%%s%%')";
-    }
-    $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, u.name FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE $where"), $arg, 0, 10);
-
-    $matches = array();
-    while ($node = db_fetch_object($result)) {
-      $name = empty($node->name) ? variable_get('anonymous', t('Anonymous')) : check_plain($node->name);
-      $matches[$node->title . " [nid: $node->nid]"] = '<span class="autocomplete_title">'. check_plain($node->title) .'</span> <span class="autocomplete_user">('. t('by @user', array('@user' => $name)) .')</span>';
-    }
-    drupal_set_header('Content-Type: text/javascript; charset=utf-8');
-    print drupal_to_js($matches);
-  }
-}
+}
\ No newline at end of file
Index: panels/panels.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels.install,v
retrieving revision 1.1.6.36
diff -u -r1.1.6.36 panels.install
--- panels/panels.install	31 Mar 2008 06:17:42 -0000	1.1.6.36
+++ panels/panels.install	30 Apr 2008 10:19:19 -0000
@@ -4,158 +4,251 @@
 /**
  * Install the panels tables
  */
-function panels_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'pgsql':
-      db_query(<<<EOT
-        CREATE TABLE {panels_page} (
-          pid integer NOT NULL DEFAULT 0,
-          name varchar(255) UNIQUE,
-          did integer,
-          title varchar(128),
-          access varchar(128),
-          path varchar(128),
-          css_id varchar(128),
-          css text,
-          arguments text,
-          displays text,
-          contexts text,
-          relationships text,
-          no_blocks smallint DEFAULT 0,
-          -- menu fields
-          menu smallint DEFAULT 0,
-          menu_tab smallint,
-          menu_tab_weight smallint,
-          menu_title varchar(255),
-          menu_tab_default smallint,
-          menu_tab_default_parent_type varchar(10),
-          menu_parent_title varchar(255),
-          menu_parent_tab_weight smallint,
-          PRIMARY KEY (pid)
-        );
-EOT
-      );
-      db_query("CREATE SEQUENCE {panels_page}_pid_seq;");
-      db_query("CREATE INDEX {panels_page}_path_idx ON {panels_page} (path);");
-      db_query("CREATE INDEX {panels_page}_name_idx ON {panels_page} (name);");
-
-      db_query(<<<EOT
-        CREATE TABLE {panels_display} (
-          did integer NOT NULL DEFAULT 0,
-          name varchar(255) UNIQUE,
-          layout varchar(32),
-          layout_settings text,
-          panel_settings text,
-          cache text,
-          PRIMARY KEY (did)
-        );
-EOT
-      );
-      db_query("CREATE SEQUENCE {panels_display}_did_seq;");
-      db_query("CREATE INDEX {panels_display}_name_idx ON {panels_page} (name);");
-
-      db_query(<<<EOT
-        CREATE TABLE {panels_pane} (
-          pid integer NOT NULL DEFAULT 0,
-          did integer NOT NULL DEFAULT 0,
-          panel varchar(32),
-          type varchar(32),
-          subtype varchar(64),
-          access varchar(128),
-          configuration text,
-          cache text,
-          position smallint,
-          PRIMARY KEY (pid)
-        );
-EOT
-      );
-      db_query("CREATE SEQUENCE {panels_pane}_pid_seq;");
-      db_query("CREATE INDEX {panels_pane}_did_idx ON {panels_pane} (did);");
-      db_query(<<<EOT
-        CREATE TABLE {panels_object_cache} (
-          sid varchar(64),
-          did integer,
-          obj varchar(255),
-          timestamp integer,
-          data text
-        );
-EOT
-      );
-      db_query("CREATE INDEX {panels_object_cache}_idx ON {panels_object_cache} (sid, obj, did);");
-      db_query("CREATE INDEX {panels_object_cache}_time_idx ON {panels_object_cache} (timestamp);");
-      break;
-    case 'mysql':
-    case 'mysqli':
-      db_query(<<<EOT
-        CREATE TABLE {panels_page} (
-          pid int(10) NOT NULL DEFAULT 0 PRIMARY KEY,
-          name varchar(255) UNIQUE,
-          did int(10),
-          title varchar(128),
-          access varchar(128),
-          path varchar(128),
-          css_id varchar(128),
-          css longtext,
-          arguments longtext,
-          displays longtext,
-          contexts longtext,
-          relationships longtext,
-          no_blocks int(1) DEFAULT 0,
-          -- menu fields
-          menu int(1) DEFAULT 0,
-          menu_tab int(1),
-          menu_tab_weight int(4),
-          menu_title varchar(255),
-          menu_tab_default int(1),
-          menu_tab_default_parent_type varchar(10),
-          menu_parent_title varchar(255),
-          menu_parent_tab_weight int(4),
-          KEY path (path)
-        )/*!40100 DEFAULT CHARACTER SET utf8 */
-EOT
-      );
+function panels_schema() {
+  $schema = array();
+  $schema['panels_page'] = array(
+    'fields' => array(
+      'pid' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'name' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE,
+      ),
+      'did' => array(
+        'type' => 'int',
+        'not null' => FALSE,
+      ),
+      'title' => array(
+        'type' => 'varchar',
+        'length' => '128',
+        'not null' => FALSE,
+      ),
+      'access' => array(
+        'type' => 'varchar',
+        'length' => '128',
+        'not null' => FALSE,
+      ),
+      'path' => array(
+        'type' => 'varchar',
+        'length' => '128',
+        'not null' => FALSE,
+      ),
+      'css_id' => array(
+        'type' => 'varchar',
+        'length' => '128',
+        'not null' => FALSE,
+      ),
+      'css' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE,
+      ),
+      'arguments' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE,
+      ),
+      'displays' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE,
+      ),
+      'contexts' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE,
+      ),
+      'relationships' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE,
+      ),
+      'no_blocks' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => FALSE,
+        'default' => 0,
+      ),
+      'menu' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => FALSE,
+        'default' => 0,
+      ),
+      'menu_tab' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => FALSE,
+      ),
+      'menu_tab_weight' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => FALSE,
+      ),
+      'menu_title' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE,
+      ),
+      'menu_tab_default' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => FALSE,
+      ),
+      'menu_tab_default_parent_type' => array(
+        'type' => 'varchar',
+        'length' => '10',
+        'not null' => FALSE,
+      ),
+      'menu_parent_title' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE,
+      ),
+      'menu_parent_tab_weight' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => FALSE,
+      )
+    ),
+    'primary key' => array('pid'),
+    'unique keys' => array(
+      'name' => array('name'),
+    ),
+    'indexes' => array(
+      'path_idx' => array('path'),
+    ),
+  );
+  $schema['panels_display'] = array(
+    'fields' => array(
+      'did' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'name' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE,
+      ),
+      'layout' => array(
+        'type' => 'varchar',
+        'length' => '32',
+        'not null' => FALSE,
+      ),
+      'layout_settings' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE,
+      ),
+      'panel_settings' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE,
+      ),
+      'cache' => array(
+        'type' => 'text',
+        'not null' => FALSE,
+      )
+    ),
+    'primary key' => array('did'),
+    'unique keys' => array(
+      'name' => array('name'),
+    ),
+  );
+  $schema['panels_pane'] = array(
+    'fields' => array(
+      'pid' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'did' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'panel' => array(
+        'type' => 'varchar',
+        'length' => '32',
+        'not null' => FALSE
+      ),
+      'type' => array(
+        'type' => 'varchar',
+        'length' => '32',
+        'not null' => FALSE
+      ),
+      'subtype' => array(
+        'type' => 'varchar',
+        'length' => '64',
+        'not null' => FALSE
+      ),
+      'access' => array(
+        'type' => 'varchar',
+        'length' => '128',
+        'not null' => FALSE
+      ),
+      'configuration' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE
+      ),
+      'cache' => array(
+        'type' => 'text',
+        'size' => 'big',
+        'not null' => FALSE
+      ),
+      'position' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => FALSE
+      ),
+    ),
+    'primary key' => array('pid'),
+    'indexes' => array(
+      'did_idx' => array('did')
+    ),
+  );
+  $schema['panels_object_cache'] = array(
+    'fields' => array(
+      'sid' => array(
+        'type' => 'varchar',
+        'length' => '64',
+        'not null' => FALSE,
+      ),
+      'did' => array(
+        'type' => 'int',
+        'not null' => FALSE,
+      ),
+      'obj' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE
+      ),
+      'data' => array(
+        'type' => 'text',
+        'not null' => FALSE
+      ),
+      'timestamp' => array(
+        'type' => 'int',
+        'not null' => FALSE,
+      ),
+    ),
+    'indexes' => array(
+      'idx' => array('sid', 'obj', 'did'),
+      'time_idx' => array('timestamp')
+    ),
+  );
+  return $schema;
+}
 
-      db_query(<<<EOT
-        CREATE TABLE {panels_display} (
-          did INT(10) NOT NULL DEFAULT 0 PRIMARY KEY,
-          name varchar(255) UNIQUE,
-          layout VARCHAR(32),
-          layout_settings longtext,
-          panel_settings longtext,
-          cache text
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */
-EOT
-      );
 
-      db_query(<<<EOT
-        CREATE TABLE {panels_pane} (
-          pid int(10) NOT NULL DEFAULT 0 PRIMARY KEY,
-          did int(10) NOT NULL DEFAULT 0,
-          panel varchar(32),
-          type varchar(32),
-          subtype varchar(64),
-          access varchar(128),
-          configuration longtext,
-          cache longtext,
-          position int(5),
-          KEY (did)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */
-EOT
-      );
-      db_query(<<<EOT
-        CREATE TABLE {panels_object_cache} (
-          sid varchar(64),
-          did integer,
-          obj varchar(255),
-          data longtext,
-          timestamp integer,
-          KEY (sid, obj, did),
-          KEY (timestamp)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */
-EOT
-      );
-  }
+function panels_install() {
   db_query("UPDATE {system} SET weight = 10 WHERE name = 'panels'");
+  cache_clear_all();
+
+  drupal_install_schema('panels'); 
 
   if (!module_exists('panels_page')) {
     drupal_set_message(t('It is recommended that you also enable the Panels page module.'));
@@ -163,24 +256,7 @@
 }
 
 function panels_uninstall() {
-  switch ($GLOBALS['db_type']) {
-    case 'pgsql':
-      db_query("DROP SEQUENCE {panels_page}_pid_seq");
-      db_query("DROP SEQUENCE {panels_pane}_pid_seq");
-      db_query("DROP SEQUENCE {panels_display}_did_seq");
-      db_query("DROP TABLE {panels_display}");
-      db_query("DROP TABLE {panels_pane}");
-      db_query("DROP TABLE {panels_page}");
-      db_query("DROP TABLE {panels_object_cache}");
-      break;
-    case 'mysql':
-    case 'mysqli':
-      db_query("DROP TABLE IF EXISTS {panels_display}");
-      db_query("DROP TABLE IF EXISTS {panels_pane}");
-      db_query("DROP TABLE IF EXISTS {panels_page}");
-      db_query("DROP TABLE IF EXISTS {panels_object_cache}");
-      break;
-  }
+  drupal_uninstall_schema('panels');
 }
 
 /**
Index: panels/styles/rounded_corners.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/styles/Attic/rounded_corners.inc,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 rounded_corners.inc
--- panels/styles/rounded_corners.inc	8 Jan 2008 18:03:08 -0000	1.1.2.4
+++ panels/styles/rounded_corners.inc	30 Apr 2008 10:19:21 -0000
@@ -18,6 +18,8 @@
       'title' => t('Rounded corners'),
       'description' => t('Presents the panes or panels with a rounded corner box around them'),
       'render panel' => 'panels_rounded_corners_style_render_panel',
+      'theme' => 'panels_rounded_corners_style_render_panel',
+      'theme arguments' => array('display', 'panel_id', 'panes', 'settings'),
       'settings form' => 'panels_rounded_corners_style_settings_form',
     ),
   );
Index: panels/styles/list.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/styles/Attic/list.inc,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 list.inc
--- panels/styles/list.inc	8 Jan 2008 18:03:08 -0000	1.1.2.6
+++ panels/styles/list.inc	30 Apr 2008 10:19:21 -0000
@@ -18,6 +18,8 @@
       'title' => t('List'),
       'description' => t('Presents the panes in the form of an HTML list.'),
       'render panel' => 'panels_list_style_render_panel',
+      'theme' => 'panels_list_style_render_panel',
+      'theme arguments' => array('display', 'panel_id', 'panes', 'settings'),
       'settings form' => 'panels_list_style_settings_form',
       'settings validate' => 'panels_list_style_settings_validate',
     ),
Index: panels/styles/default.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/styles/Attic/default.inc,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 default.inc
--- panels/styles/default.inc	8 Jan 2008 18:03:08 -0000	1.1.2.4
+++ panels/styles/default.inc	30 Apr 2008 10:19:21 -0000
@@ -18,6 +18,8 @@
       'title' => t('Default'),
       'description' => t('The default panel rendering style; displays each pane with a separator.'),
       'render panel' => 'panels_default_style_render_panel',
+      'theme' => 'panels_default_style_render_panel',
+      'theme arguments' => array('display', 'panel_id', 'panes', 'settings'),
     ),
   );
 }
Index: panels/panels_page/panels_page.admin.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels_page/Attic/panels_page.admin.inc,v
retrieving revision 1.1.2.37
diff -u -r1.1.2.37 panels_page.admin.inc
--- panels/panels_page/panels_page.admin.inc	24 Jan 2008 17:51:13 -0000	1.1.2.37
+++ panels/panels_page/panels_page.admin.inc	30 Apr 2008 10:19:21 -0000
@@ -3,10 +3,12 @@
 /**
  * @file panels_page.admin.inc Administrative screens and functions for panel pages
  */
+
 /**
  * Provide a list of panels, with links to edit or delete them.
  */
 function panels_page_list_page() {
+  panels_load_include('plugins');
   $layouts = panels_get_layouts();
   $items = array();
   $sorts = array();
@@ -32,10 +34,10 @@
     }
     else {
       if (empty($panel_page->disabled)) {
-        $ops[] = l(t('Disable'), "admin/panels/panel-page/disable/$panel_page->name", NULL, drupal_get_destination());
+        $ops[] = l(t('Disable'), "admin/panels/panel-page/disable/$panel_page->name", array('query' => drupal_get_destination()));
       }
       else {
-        $ops[] = l(t('Enable'), "admin/panels/panel-page/enable/$panel_page->name", NULL, drupal_get_destination());
+        $ops[] = l(t('Enable'), "admin/panels/panel-page/enable/$panel_page->name", array('query' => drupal_get_destination()));
       }
     }
 
@@ -118,58 +120,56 @@
 /*
  * Provide a form to confirm deletion of a panel page.
  */
-function panels_page_delete_confirm($panel_page) {
-  if (!is_object($panel_page)) {
-    $panel_page = panels_page_load($panel_page);
-  }
-  $form['pid'] = array('#type' => 'value', '#value' => $panel_page->pid);
-  $form['did'] = array('#type' => 'value', '#value' => $panel_page->did);
-  if ($panel_page->type != t('Overridden')) {
-    return confirm_form( $form,
-      t('Are you sure you want to delete "@title"?', array('@title' => panels_page_get_title($panel_page))),
-      $_GET['destination'] ? $_GET['destination'] : 'admin/panels/panel-page',
-      t('This action cannot be undone.'),
-      t('Delete'), t('Cancel')
-    );
+function panels_page_delete_confirm($form_state, $panel_page) {
+  $form_state['panel_page'] = $panel_page;
+  if ($panel_page->type == t('Overridden')) {
+    $question = 'Are you sure you want to revert %title to its default setup?';   
+    $action = t('Revert');
   }
   else {
-    return confirm_form( $form,
-      t('Are you sure you want to revert "@title" to its default setup?', array('@title' => panels_page_get_title($panel_page))),
-      $_GET['destination'] ? $_GET['destination'] : 'admin/panels/panel-page',
-      t('This action cannot be undone.'),
-      t('Revert'), t('Cancel')
-    );
+    $question = 'Are you sure you want to delete %title?';
+    $action = t('Delete');
   }
+  return confirm_form(
+    $form,
+    t($question, array('%title' => panels_page_get_title($panel_page))),
+    'admin/panels/panel-page',
+    t('This action cannot be undone.'),
+    $action, t('Cancel')
+  );
 }
 
-/*
- * Handle the submit button to delete a panel page.
- */
-function panels_page_delete_confirm_submit($formid, $form) {
-  if ($form['confirm']) {
-    panels_page_delete((object) $form);
-    // TODO: Is this necessary or did we feed it the location already?
-    return 'admin/panels/panel-page';
+function panels_page_delete_confirm_submit($form, &$form_state) {
+  $panel_page = $form_state['panel_page'];
+  if ($panel_page->type == t('Overridden')) {
+  	drupal_set_message(t('The panel page %name has been reverted to its to its default setup.', array('%name' => $panel_page->name)));
   }
+  else {
+  	drupal_set_message(t('The panel page %name has been deleted.', array('%name' => $panel_page->name)));
+  }
+  panels_page_delete($panel_page);
+  $form_state['redirect'] = 'admin/panels/panel-page';
 }
 
 /**
- * Handle the add panel-page page
+ * Menu callback: Add a new panel page.
+ * 
+ * @param $layout_name
+ *   (optional) Short name of a page layout (if already chosen).
  */
-function panels_page_add_page($layout = NULL) {
+function panels_page_add($layout = NULL) {
+  panels_load_include('plugins');
   $layouts = panels_get_layouts();
 
-  if ($layout === NULL) {
-    foreach ($layouts as $id => $layout) {
-      $output .= panels_print_layout_link($id, $layout, $_GET['q'] . '/' . $id);
+  // If not already given, choose a page layout first.
+  if ($layout === NULL || !isset($layouts[$layout])) {
+    $output .= t('<p>Choose a layout for your new page from the list below.</p>');
+    foreach ($layouts as $name => $data) {
+      $output .= panels_print_layout_link($name, $data, $_GET['q'] . "/$name");
     }
     return $output;
   }
 
-  if (!$layouts[$layout]) {
-    return drupal_not_found();
-  }
-
   $panel_page->display = panels_new_display();
   $panel_page->display->layout = $layout;
   $panel_page->pid = 'new';
@@ -179,16 +179,71 @@
   return drupal_get_form('panels_page_edit_form', panels_page_sanitize($panel_page));
 }
 
-
 /**
- * Edit a panel page. Called from both the add and edit points to provide
- * for common flow.
+ * Form constructor: Import panel page
  */
-function panels_page_edit($panel_page) {
-  if (!is_object($panel_page)) {
-    $panel_page = panels_page_load($panel_page);
+function panels_page_import_form($form_state) {
+  if (empty($form_state['storage'])) {
+    // Step 1:
+    $form['import'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Panel page code'),
+      '#cols' => 60,
+      '#rows' => 15,
+      '#description' => t('Cut and paste the results of an Export Panel Page here.'),
+    );
+    $form['submit'] = array(
+      '#type' => 'submit',
+      '#value' => t('Import'),
+    );
+  }
+  else {
+    // Step 2:
+    $panel_page = $form_state['storage']['panel_page'];
+    drupal_set_title(t('Import panel page "@s"', array('@s' => $panel_page->title)));
+    $form = panels_page_edit_form($form_state, $panel_page);
+  }
+  return $form;
+}
+
+function panels_page_import_form_validate($form, &$form_state) {
+  if ($form['import']) {
+    // Step 1:
+    eval($form_state['values']['import']);
+
+    if (isset($page)) {
+      $form_state['storage']['panel_page'] = $page;
+    }
+    else {
+      form_set_error('import', t('Unable to get a panel page out of that.'));
+    }
+  }
+  else {
+    // Step 2:
+    panels_page_edit_form_validate($form, $form_state);
+  }
+}
+
+function panels_page_import_form_submit($form, &$form_state) {
+  if ($form['import']) {
+    // Step 1:
+    $form_state['rebuild'] = TRUE;
   }
+  else {
+    // Step 2:
+    $form_state['storage'] = NULL;
+    $form_state['rebuild'] = FALSE;
+    panels_page_edit_form_submit($form, $form_state);
+  }
+}
 
+/**
+ * Menu callback: Edit a certain panel page.
+ * 
+ * @param $panel_page
+ *   A panel_page object.
+ */
+function panels_page_edit($panel_page) {
   if (empty($panel_page->display)) {
     $panel_page->display = panels_load_display($panel_page->did);
   }
@@ -198,69 +253,27 @@
 }
 
 /**
- * The form to edit the page portion of a panel.
+ * Form constructor: Edit "general" (page) settings
+ * 
+ * Called from panels_page_add, panels_page_edit and panels_page_import.
  */
-function panels_page_edit_form($panel_page, $next = NULL) {
+function panels_page_edit_form($form_state, $panel_page) {
   panels_load_include('common');
+  panels_load_include('plugins');
+  
   drupal_add_css(panels_get_path('css/panels_admin.css'));
   $layout = panels_get_layout($panel_page->display->layout);
-
-  $form['pid'] = array(
-    '#type' => 'value',
-    '#value' => $panel_page->pid,
-  );
-
-  $form['panel_page'] = array(
-    '#type' => 'value',
-    '#value' => $panel_page
-  );
-
-  $form['right'] = array(
-    '#prefix' => '<div class="layout-container">',
-    '#suffix' => '</div>',
-  );
+  kprint_r($form_state);
+  $form_state['panel_page'] = $panel_page;
 
   $form['left'] = array(
     '#prefix' => '<div class="panel-page-info-container">',
     '#suffix' => '</div>',
   );
-
   $form['left']['info'] = array(
     '#type' => 'fieldset',
     '#title' => t('Page settings'),
   );
-
-  $form['right']['layout'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Layout'),
-  );
-
-  $form['right']['layout']['layout-icon'] = array(
-    '#value' => panels_print_layout_icon($panel_page->display->layout, $layout),
-  );
-
-  $form['right']['layout']['layout-display'] = array(
-    '#value' => check_plain($layout['title']),
-  );
-
-  $panel_page->context = $panel_page->display->context = panels_context_load_contexts($panel_page);
-
-  $form['right']['layout']['layout-content'] = array(
-    '#value' => theme('panels_common_content_list', $panel_page->display), //$content,
-  );
-
-  $contexts = theme('panels_common_context_list', $panel_page);
-  if ($contexts) {
-    $form['right']['context'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Contexts'),
-    );
-
-    $form['right']['context']['context'] = array(
-      '#value' => $contexts,
-    );
-  }
-
   $form['left']['info']['name'] = array(
     '#type' => 'textfield',
     '#size' => 35,
@@ -269,7 +282,6 @@
     '#description' => t('A unique name used to identify this panel page internally. It must be only be alpha characters and underscores. No spaces, numbers or uppercase characters.'),
     '#required' => TRUE,
   );
-
   $form['left']['info']['title'] = array(
     '#type' => 'textfield',
     '#size' => 35,
@@ -277,7 +289,6 @@
     '#title' => t('Page title'),
     '#description' => t('The page title for this panels layout'),
   );
-
   $form['left']['info']['css_id'] = array(
     '#type' => 'textfield',
     '#size' => 35,
@@ -285,7 +296,6 @@
     '#title' => t('CSS ID'),
     '#description' => t('The CSS ID to apply to this page'),
   );
-
   $form['left']['info']['path'] = array(
     '#type' => 'textfield',
     '#size' => 35,
@@ -295,7 +305,40 @@
     '#required' => TRUE,
   );
 
-  $label = ($panel_page->pid == 'new') ? t('Next') : t('Save');
+  $form['right'] = array(
+    '#prefix' => '<div class="layout-container">',
+    '#suffix' => '</div>',
+    '#weight' => -1,
+  );
+  $form['right']['layout'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Layout'),
+  );
+  $form['right']['layout']['layout-icon'] = array(
+    '#value' => panels_print_layout_icon($layout),
+  );
+  $form['right']['layout']['layout-display'] = array(
+    '#value' => check_plain($layout['title']),
+  );
+
+  $panel_page->context = $panel_page->display->context = panels_context_load_contexts($panel_page);
+  $form['right']['layout']['layout-content'] = array(
+    '#value' => theme('panels_common_content_list', $panel_page->display),
+  );
+
+  $contexts = theme('panels_common_context_list', $panel_page);
+  if ($contexts) {
+    $form['right']['context'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Contexts'),
+    );
+
+    $form['right']['context']['context'] = array(
+      '#value' => $contexts,
+    );
+  }
+
+  $label = ($panel_page->pid == 'new') ? t('Save and proceed') : t('Save');
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => $label,
@@ -304,85 +347,73 @@
   return $form;
 }
 
-/**
- * Validate a panel page edit form
- */
-function panels_page_edit_form_validate($form_id, $form_values, $form) {
-  // Test uniqueness of name:
-  if (!$form_values['name']) {
-    form_error($form['left']['info']['name'], t('Panel name is required.'));
-  }
-  else if (preg_match("/[^A-Za-z0-9_]/", $form_values['name'])) {
+function panels_page_edit_form_validate($form, &$form_state) {
+  $pid = $form_state['panel_page']->pid;
+
+  // Validate name (beyond being required):
+  $name = $form_state['values']['name'];
+  if (preg_match("/[^A-Za-z0-9_]/", $name)) {
     form_error($form['left']['info']['name'], t('Name must be alphanumeric or underscores only.'));
   }
   else {
-    $query = "SELECT pid FROM {panels_page} WHERE name = '%s'";
-    if (!empty($form_values['pid']) && is_numeric($form_values['pid'])) {
-      $query .= " AND pid != $form_values[pid]";
+    if (!empty($pid) && is_numeric($pid)) {
+      $result = db_result(db_query("SELECT pid FROM {panels_page} WHERE name = '%s' AND pid != %d", $name, $pid));
+    }
+    else {
+      $result = db_result(db_query("SELECT pid FROM {panels_page} WHERE name = '%s'", $name));
     }
-    if (db_result(db_query($query, $form_values['name']))) {
+    if ($result) {
       form_error($form['left']['info']['name'], t('Panel name must be unique.'));
     }
   }
 
-  if (!$form_values['path']) {
-    form_error($form['left']['info']['path'], t('Path is required.'));
+  // Validate path (beyond being required):
+  $path = $form_state['values']['path'];
+  if (db_result(db_query("SELECT pid FROM {panels_page} WHERE path = '%s' AND pid != %d", $path, $pid))) {
+    form_error($form['left']['info']['path'], t('Path may not be the same as another panel page path.'));
   }
-  else {
-    $result = db_result(db_query("SELECT pid FROM {panels_page} WHERE path = '%s' AND pid <> %d", $form_values['path'], $form_values['pid']));
-    if ($result) {
-      form_error($form['left']['info']['path'], t('Path may not be the same as another panel page path.'));
-    }
-
-    // validate against aliases
-    $result = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $form_values['path']));
-    if ($result) {
-      form_error($form['left']['info']['path'], t('The path you have chosen is already aliased to @src.', array('@src' => $result)));
-    }
+  else if ($result = db_result(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $path))) {
+    form_error($form['left']['info']['path'], t('The path you have chosen is already aliased to %src.', array('%src' => $result)));
   }
 }
 
-/**
- * Process submission of the panel page edit form
- */
-function panels_page_edit_form_submit($form_id, $form_values) {
-  $panel_page = $form_values['panel_page'];
+function panels_page_edit_form_submit($form, &$form_state) {
+  $panel_page = $form_state['panel_page'];
 
-  $panel_page->title  = $form_values['title'];
-  $panel_page->name  = preg_replace("/[\W]+/", '', $form_values['name']);
-  $panel_page->css_id = $form_values['css_id'];
-  $panel_page->path  = $form_values['path'];
+  $panel_page->title = $form_state['values']['title'];
+  $panel_page->name = preg_replace("/[\W]+/", '', $form_state['values']['name']);
+  $panel_page->css_id = $form_state['values']['css_id'];
+  $panel_page->path  = $form_state['values']['path'];
 
   if ($panel_page->pid == 'new') {
-    unset($_SESSION['pp_import']);
-    $pid = panels_page_save($panel_page);
-    $GLOBALS['form_values']['pid'] = $pid;
+    panels_page_save($panel_page);
+    drupal_set_message(t('Your new panel page %title has been saved.', array('%title' => $panel_page->title)));
+    
     $layout = panels_get_layout($panel_page->display->layout);
-
-    if ($layout['settings form']) {
-      return "admin/panels/panel-page/$panel_page->name/edit/settings/next";
-    }
-    return "admin/panels/panel-page/$panel_page->name/edit/advanced/next";
+    $next_page = $layout['settings form'] ? 'settings' : 'advanced';
+    $form_state['redirect'] =  "admin/panels/panel-page/$panel_page->name/edit/$next_page/next";
   }
   else {
-    drupal_set_message(t('Your changes have been saved.'));
     panels_page_save($panel_page);
+    drupal_set_message(t('Your changes have been saved.'));
   }
 }
 
 /**
- * Edit advanced settings of a panel page
+ * Menu callback: Edit 'advanced settings' of a certain panel page.
+ * 
+ * @param $panel_page
+ *   A panel_page object.
  */
-function panels_page_edit_advanced($name, $next = NULL) {
-  $panel_page = panels_page_load($name);
+function panels_page_edit_advanced($panel_page, $next = NULL) {
   drupal_set_title(check_plain(panels_page_get_title($panel_page)));
-  return drupal_get_form('panels_page_advanced_form', $panel_page, $next);
+  return drupal_get_form('panels_page_edit_advanced_form', $panel_page, $next);
 }
 
 /**
- * The form to edit the advanced settings of a panel page
+ * Form constructor: Edit 'advanced settings' of a certain panel page
  */
-function panels_page_advanced_form($panel_page, $next = NULL) {
+function panels_page_edit_advanced_form($form_state, $panel_page, $next = NULL) {
   drupal_add_css(panels_get_path('css/panels_admin.css'));
 
   $form['panel_page'] = array(
@@ -518,7 +549,7 @@
     '#description' => t('If the Parent Menu Item is being defined by this panel (if you set the %type_field to either %tab or %menu), you can specify its title here.  If blank, the menu title will be used if that is defined, or the page title if not.', array('%type_field' => t('Parent Menu Item Type'), '%tab' => t('Tab'), '%menu' => t('Normal menu item'))),
   );
 
-  $label = ($next) ? t('Next') : t('Save');
+  $label = $next ? t('Save and proceed') : t('Save');
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => $label,
@@ -527,79 +558,77 @@
   return $form;
 }
 
+function panels_page_edit_advanced_form_submit($form, &$form_state) {
+  $values = $form_state['values'];
+  $panel_page = $values['panel_page'];
+
+  $panel_page->css = $values['css'];
+  $panel_page->no_blocks = $values['no_blocks'];
+  $panel_page->menu = $values['menu'];
+  $panel_page->menu_tab = $values['menu_tab'];
+  $panel_page->menu_tab_weight = $values['menu_tab_weight'];
+  $panel_page->menu_title = $values['menu_title'];
+  $panel_page->menu_tab_default = $values['menu_tab_default'];
+  $panel_page->menu_tab_default_parent_type = $values['menu_tab_default_parent_type'];
+  $panel_page->menu_parent_title = $values['menu_parent_title'];
+  $panel_page->menu_parent_tab_weight = $values['menu_parent_tab_weight'];
 
-/**
- * Process submission of the panel page edit form
- */
-function panels_page_advanced_form_submit($form_id, $form_values) {
-  $panel_page = $form_values['panel_page'];
-
-  $panel_page->css = $form_values['css'];
-  $panel_page->no_blocks = $form_values['no_blocks'];
-  $panel_page->menu = $form_values['menu'];
-  $panel_page->menu_tab = $form_values['menu_tab'];
-  $panel_page->menu_tab_weight = $form_values['menu_tab_weight'];
-  $panel_page->menu_title = $form_values['menu_title'];
-  $panel_page->menu_tab_default = $form_values['menu_tab_default'];
-  $panel_page->menu_tab_default_parent_type = $form_values['menu_tab_default_parent_type'];
-  $panel_page->menu_parent_title = $form_values['menu_parent_title'];
-  $panel_page->menu_parent_tab_weight = $form_values['menu_parent_tab_weight'];
-
-  $panel_page->access = array_keys(array_filter($form_values['access']));
+  $panel_page->access = array_keys(array_filter($values['access']));
 
-  drupal_set_message(t('Your changes have been saved.'));
   panels_page_save($panel_page);
-  if ($form_values['submit'] == t('Next')) {
-    return "admin/panels/panel-page/$panel_page->name/edit/context/next";
+  drupal_set_message(t('Your changes have been saved.'));
+  if ($form_state['clicked_button']['#value'] == t('Save and proceed')) {
+    $form_state['redirect'] = "admin/panels/panel-page/$panel_page->name/edit/context/next";
   }
 }
 
 /**
- * Edit advanced settings of a panel page
+ * Menu callback: Edit 'context' of a certain panel page.
+ * 
+ * @param obj $panel_page
+ *   A panel_page object.
  */
-function panels_page_edit_context($name, $next = NULL) {
+function panels_page_edit_context($panel_page, $next = NULL) {
   if (!empty($_POST)) {
-    $panel_page = panels_common_cache_get('panel_object:panel_page', $name);
+    $panel_page = panels_common_cache_get('panel_object:panel_page', $panel_page->name);
   }
   else {
-    $panel_page = panels_page_load($name);
     panels_common_cache_set('panel_object:panel_page', $name, $panel_page);
   }
 
   drupal_set_title(check_plain(panels_page_get_title($panel_page)));
-  return drupal_get_form('panels_page_context_form', $panel_page, $next);
+  return drupal_get_form('panels_page_edit_context_form', $panel_page, $next);
 }
 
 /**
- * The form to edit the context settings of a panel page
+ * Form constructor: Edit 'context' of a certain panel page.
  */
-function panels_page_context_form($panel_page, $next = NULL) {
+function panels_page_edit_context_form($form_state, $panel_page, $next = NULL) {
   drupal_add_css(panels_get_path('css/panels_admin.css'));
+  panels_load_include('plugins');
+  panels_load_include('common');
+
   $layout = panels_get_layout($panel_page->display->layout);
 
   $form['panel_page'] = array(
     '#type' => 'value',
     '#value' => $panel_page
   );
-
   $form['right'] = array(
     '#prefix' => '<div class="right-container">',
     '#suffix' => '</div>',
   );
-
   $form['left'] = array(
     '#prefix' => '<div class="left-container">',
     '#suffix' => '</div>',
   );
 
-  panels_load_include('common');
-
   $settings =  panels_common_add_argument_form('panel_page', $form, $form['left']['arguments_table'], $panel_page);
   $settings += panels_common_add_context_form('panel_page', $form, $form['right']['contexts_table'], $panel_page);
   $settings += panels_common_add_relationship_form('panel_page', $form, $form['left']['relationships_table'], $panel_page);
   panels_common_add_context_js($settings);
 
-  $label = ($next) ? t('Next') : t('Save');
+  $label = $next ? t('Save and proceed') : t('Save');
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => $label,
@@ -608,17 +637,13 @@
   return $form;
 }
 
-
-/**
- * Process submission of the panel page edit form
- */
-function panels_page_context_form_submit($form_id, $form_values) {
-  $panel_page = $form_values['panel_page'];
+function panels_page_edit_context_form_submit($form, &$form_state) {
+  $panel_page = $form_state['values']['panel_page'];
 
   // Organize these from the common form.
-  panels_common_save_context('argument', $panel_page->arguments, $form_values);
-  panels_common_save_context('context', $panel_page->contexts, $form_values);
-  panels_common_save_context('relationship', $panel_page->relationships, $form_values);
+  panels_common_save_context('argument', $panel_page->arguments, $form_state['values']);
+  panels_common_save_context('context', $panel_page->contexts, $form_state['values']);
+  panels_common_save_context('relationship', $panel_page->relationships, $form_state['values']);
 
   // Match up our displays, carry them forward and add new ones.
   $old_displays = $panel_page->displays;
@@ -659,29 +684,38 @@
     }
   }
 
-  drupal_set_message(t('Your changes have been saved.'));
   panels_page_save($panel_page);
+  drupal_set_message(t('Your changes have been saved.'));
   panels_common_cache_clear('panel_object:panel_page', $panel_page->name);
-  if ($form_values['submit'] == t('Next')) {
-    return "admin/panels/panel-page/$panel_page->name/edit/content";
+  if ($form_state['clicked_button']['#value'] == t('Save and proceed')) {
+    $form_state['redirect'] = "admin/panels/panel-page/$panel_page->name/edit/content";
   }
 }
 
 /**
- * Pass through to the panels layout editor.
+ * Menu callback: Edit 'layout' of a certain panel page.
+ * 
+ * Pass through to panels_edit_layout_form().
  */
 function panels_page_edit_layout($panel_page, $did = NULL) {
-  if (!is_object($panel_page)) {
-    $panel_page = panels_page_load($panel_page);
-  }
-
   $display = panels_page_fetch_display($panel_page, $did);
 
   // The following form will return the $display upon successful submit, if
   // we didn't send the $dest. Which we don't, here. That way we can update
   // our panel_page if necessary and do our own goto.
-  $output = panels_edit_layout($panel_page->display, t('Save'));
-  if (is_object($output)) {
+  $old_display = $display;
+  // $output = panels_edit_layout($panel_page->display, t('Save'));
+  
+  panels_load_include('display_edit');
+  panels_load_include('plugins');
+  $output = drupal_get_form('panels_edit_layout_form', $display, NULL);  
+  
+  if ($old_display != $display) {
+    // drupal_set_message($old_display->layout . ' ==> ' . $display->layout, 'warning');
+  } else {
+    // drupal_set_message($old_display->layout);
+  }
+/*  if (is_object($output)) {
     // If this is a default page, and was saved, we have to make it real.
     panels_page_set_display($panel_page, $did, $output);
 
@@ -690,20 +724,18 @@
       $dest .= "/$did";
     }
     drupal_goto($dest);
-  }
+  }*/
 
   drupal_set_title(check_plain(panels_page_get_title($panel_page)));
   return $output;
 }
 
 /**
- * Pass through to the panels layout settings editor.
+ * Menu callback: Edit 'layout settings' of a certain panel page.
+ * 
+ * Pass through to panels_edit_layout_settings().
  */
 function panels_page_edit_layout_settings($panel_page, $did = NULL, $next = NULL) {
-  if (!is_object($panel_page)) {
-    $panel_page = panels_page_load($panel_page);
-  }
-
   $display = panels_page_fetch_display($panel_page, $did);
 
   if (empty($next)) {
@@ -731,13 +763,14 @@
 }
 
 /**
- * Pass through to the panels content editor.
+ * Menu callback: Edit 'content' of a certain panel page.
+ * 
+ * Pass through to panels_edit().
  */
 function panels_page_edit_content($panel_page, $did = NULL) {
-  if (!is_object($panel_page)) {
-    $panel_page = panels_page_load($panel_page);
-  }
-
+  panels_load_include('common');
+  panels_load_include('plugins');
+  
   $display = panels_page_fetch_display($panel_page, $did);
 
   // Collect a list of contexts required by the arguments on this page.
@@ -747,11 +780,10 @@
   $display->args = array();
 
   // Get a list of available content.
-  require_once drupal_get_path('module', 'panels') . '/includes/common.inc';
   $content_types = panels_common_get_allowed_types('panels_page', $contexts);
-
+  
   $output = panels_edit($display, NULL, $content_types);
-  if (is_object($output)) {
+  /*if (is_object($output)) {
     // If this is a default page, and was saved, we have to make it real.
     panels_page_set_display($panel_page, $did, $output);
 
@@ -761,8 +793,7 @@
       $dest .= "/$did";
     }
     drupal_goto($dest);
-  }
-
+  }*/
   // Print this with theme('page') so that blocks are disabled while editing a display.
   // This is important because negative margins in common block layouts (i.e, Garland)
   // messes up the drag & drop.
@@ -773,10 +804,7 @@
 /**
  * Page callback to export a panel page to PHP code.
  */
-function panels_page_edit_export($panel_page) {
-  if (!is_object($panel_page)) {
-    $panel_page = panels_page_load($panel_page);
-  }
+function panels_page_edit_export_form($form_state, $panel_page) {
   drupal_set_title(check_plain($panel_page->title));
   $code = panels_page_export($panel_page);
 
@@ -790,60 +818,9 @@
 }
 
 /*
- * Page callback to import a panel page from PHP code.
+ * Form constructor: admin view
  */
-function panels_page_import_page() {
-  if ($_POST['form_id'] == 'panels_page_edit_form') {
-    $panel_page = $_SESSION['pp_import'];
-    drupal_set_title(t('Import panel page "@s"', array('@s' => $panel_page->title)));
-    return drupal_get_form('panels_page_edit_form', $panel_page);
-  }
-
-  return drupal_get_form('panels_page_import_form');
-}
-
-/*
- * Form to for the panel page import
- */
-function panels_page_import_form() {
-  $form['panel_page'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Panel page code'),
-    '#cols' => 60,
-    '#rows' => 6,
-    '#description' => t('Cut and paste the results of an Export Panel Page here.'),
-  );
-
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t("Submit"),
-  );
-
-  $form['#redirect'] = FALSE;
-  return $form;
-}
-
-/*
- * Handle the submit button on importing a panel page.
- */
-function panels_page_import_form_submit($formid, $form) {
-  ob_start();
-  eval($form['panel_page']);
-  ob_end_clean();
-
-  if (isset($page)) {
-    drupal_set_title(t('Import panel page "@s"', array('@s' => $page->title)));
-    $_SESSION['pp_import'] = $page;
-    $output = drupal_get_form('panels_page_edit_form', $page);
-    print theme('page', $output);
-    exit;
-  }
-  else {
-    drupal_set_message(t('Unable to get a panel page out of that.'));
-  }
-}
-
-function panels_page_admin_view($panel_page, $args) {
+function panels_page_admin_view_form($form_state, $panel_page, $args) {
   $form = array();
 
   $form['fieldset'] = array(
@@ -901,15 +878,15 @@
   return $form;
 }
 
-function panels_page_admin_view_submit($form_id, $form_values) {
+function panels_page_admin_view_form_submit($form, &$form_state) {
+  $url = "admin/panels/panel-page/" . $form_state['values']['panel_page']->name . "/preview";
   $count = 0;
-  $url = "admin/panels/panel-page/" . $form_values['panel_page']->name . "/preview";
-  foreach ($form_values['contexts'] as $context) {
-    $url .= "/" . $form_values["arg$count"];
+  foreach ($form_state['values']['contexts'] as $context) {
+    $url .= "/" . $form_state['values']["arg$count"];
     $count++;
   }
-  if (!empty($form_values['additional'])) {
-    $url .= "/" . $form_values['additional'];
+  if (!empty($form_state['values']['additional'])) {
+    $url .= "/" . $form_state['values']['additional'];
   }
-  return $url;
+  $form_state['redirect'] = $url;
 }
Index: panels/panels_page/panels_page.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels_page/Attic/panels_page.module,v
retrieving revision 1.1.2.41
diff -u -r1.1.2.41 panels_page.module
--- panels/panels_page/panels_page.module	21 Feb 2008 01:24:30 -0000	1.1.2.41
+++ panels/panels_page/panels_page.module	30 Apr 2008 10:19:21 -0000
@@ -4,13 +4,11 @@
 /**
  * Implementation of hook_help()
  */
-function panels_page_help($section = '') {
-  switch ($section) {
+function panels_page_help($path, $arg) {
+  switch ($path) {
     case 'admin/panels/panel-page':
     case 'admin/panels/panel-page/list':
       return t('<p>You may peruse a list of your current panels layouts and edit them, or click add to create a new page.</p>');
-    case 'admin/panels/panel-page/add':
-      return t('<p>Choose a layout for your new page from the list below.</p>');
   }
 }
 
@@ -24,355 +22,328 @@
 /**
  * Implementation of hook_menu()
  */
-function panels_page_menu($may_cache) {
+function panels_page_menu() {
   $items = array();
-  $panels = panels_page_load_all();
-  if ($may_cache) {
-    $access = user_access('create panel-pages');
-    $items[] = array(
-      'path' => 'admin/panels/panel-page',
-      'title' => t('Panel pages'),
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_list_page'),
-      'description' => t('Create and administer panel-pages (complex layout pages with URLs).'),
-    );
-    $items[] = array(
-      'path' => 'admin/panels/panel-page/list',
-      'title' => t('List'),
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_list_page'),
-      'weight' => -10,
-      'type' => MENU_DEFAULT_LOCAL_TASK,
-    );
-    $items[] = array(
-      'path' => 'admin/panels/panel-page/add',
-      'title' => t('Add'),
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_add_page'),
-      'type' => MENU_LOCAL_TASK,
-    );
-    $items[] = array(
-      'path' => 'admin/panels/panel-page/import',
-      'title' => t('Import'),
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_import_page'),
-      'type' => MENU_LOCAL_TASK,
-    );
-    $items[] = array(
-      'path' => 'admin/panels/panel-page/settings',
-      'title' => t('Settings'),
-      'access' => $access,
-      'callback' => 'panels_page_settings',
-      'weight' => 5,
-      'type' => MENU_LOCAL_TASK,
-    );
-    $items[] = array(
-      'path' => 'admin/panels/panel-page/disable',
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_disable_page'),
-      'weight' => -1,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'admin/panels/panel-page/enable',
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_enable_page'),
-      'weight' => -1,
-      'type' => MENU_CALLBACK,
-    );
-
-    // Ajax responder
-    $items[] = array(
-      'path' => 'panels/argument/ajax/add',
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_ajax_argument_add'),
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'panels/argument/ajax/edit',
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_ajax_argument_edit'),
-      'type' => MENU_CALLBACK,
-    );
-
-    // Ajax responder
-    $items[] = array(
-      'path' => 'panels/relationship/ajax/add',
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_ajax_relationship_add'),
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'panels/relationship/ajax/edit',
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_ajax_relationship_edit'),
-      'type' => MENU_CALLBACK,
-    );
-
-    // Ajax responder
-    $items[] = array(
-      'path' => 'panels/context/ajax/add',
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_ajax_context_add'),
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'panels/context/ajax/edit',
-      'access' => $access,
-      'callback' => 'panels_page_passthru',
-      'callback arguments' => array('panels_page_ajax_context_edit'),
-      'type' => MENU_CALLBACK,
-    );
-
-    // Get all panels and, if enabled, create menu items.
-    foreach ($panels as $panel_page) {
-      if (empty($panel_page->disabled)) {
-        // Only create menu items based on the path if it's not a variable path.
-        if (strpos($panel_page->path, '%') === FALSE) {
-          _panels_page_create_menu_item($items, $panel_page, $panel_page->path, array($panel_page->name, FALSE));
-          // DEBUG: Above is now creating only the basic menu item, not the admin items.
-        }
-        panels_page_admin_menu_items($items, 'admin/panels/panel-page/' . $panel_page->name, $panel_page);
-      }
-    }
-  }
-  else {
-    // Look for panels with variable arguments.
-    // Build an array of $urls because 'real' URLs will take precedence over
-    // argument filled URLs
-    $urls = array();
-    foreach ($panels as $panel_page) {
-      $url[$panel_page->path] = TRUE;
-    }
-
-    $plugins_loaded = FALSE;
-    foreach ($panels as $panel_page) {
-      if (strpos($panel_page->path, '%') !== FALSE) {
-        $path = explode('/', $panel_page->path);
-        $match = TRUE;
-        foreach ($path as $id => $chunk) {
-          if ($chunk != '%' && $chunk != arg($id)) {
-            $match = FALSE;
-            break;
-          }
-        }
-        // It's a MATCH! Construct the URL
-        if ($match) {
-          $args = array($panel_page, FALSE);
-          reset($panel_page->arguments);
-          foreach ($path as $id => $chunk) {
-            if ($chunk != '%') {
-              continue;
-            }
-            // For arguments that are embedded in the URL, we require the
-            // argument handler to return a context, if there is an argument handler.
-            $argument = current($panel_page->arguments);
-            if ($argument) {
-              // Try to avoid loading the plugins code unless necessary.
-              if (!$plugins_loaded) {
-                panels_load_include('plugins');
-                $plugins_loaded = TRUE;
-              }
-              $context = panels_argument_get_context($argument, arg($id));
-              if (!$context) {
-                break;
-              }
-              $panel_page->context[panels_argument_context_id($argument)] = $context;
-            }
-            $path[$id] = arg($id);
-            $args[] = arg($id);
-            next($panel_page->arguments);
-          }
-          _panels_page_create_menu_item($items, $panel_page, implode('/', $path), $args);
-          // DEBUG: Above is now creating only the basic menu item, not the admin items.
-        }
-      }
-    }
-  }
+  $panel_pages = panels_page_load_all();
+  _panels_page_menu_ajax($items);
+  _panels_page_menu_admin($items, $panel_pages);
+  _panels_page_menu_panel($items, $panel_pages);
   return $items;
 }
-
-/**
- * Helper function to add a menu item for a panel.
- */
-function panels_page_admin_menu_items(&$items, $base, $page) {
-  $access = user_access('create panel-pages');
-
-  $items[] = array(
-    'path' => $base,
-    'title' => t('Preview'),
-    'access' => $access,
-    'callback' => 'panels_page_view_page',
-    'callback arguments' => array($page->name, TRUE),
+function _panels_page_menu_ajax(&$items) {
+  // Ajax responder
+  $items['panels/argument/ajax/add'] = array(
+    'page callback' => 'panels_page_passthru',
+    'page arguments' => array('panels_page_ajax_argument_add'),
+    'access arguments' => array('create panel-pages'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['panels/argument/ajax/edit'] = array(
+    'page callback' => 'panels_page_passthru',
+    'page arguments' => array('panels_page_ajax_argument_edit'),
+    'access arguments' => array('create panel-pages'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['panels/relationship/ajax/add'] = array(
+    'page callback' => 'panels_page_passthru',
+    'page arguments' => array('panels_page_ajax_relationship_add'),
+    'access arguments' => array('create panel-pages'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['panels/relationship/ajax/edit'] = array(
+    'page callback' => 'panels_page_passthru',
+    'page arguments' => array('panels_page_ajax_relationship_edit'),
+    'access arguments' => array('create panel-pages'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['panels/context/ajax/add'] = array(
+    'page callback' => 'panels_page_passthru',
+    'page arguments' => array('panels_page_ajax_context_add'),
+    'access arguments' => array('create panel-pages'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['panels/context/ajax/edit'] = array(
+    'page callback' => 'panels_page_passthru',
+    'page arguments' => array('panels_page_ajax_context_edit'),
+    'access arguments' => array('create panel-pages'),
+    'type' => MENU_CALLBACK,
+  );
+}
+function _panels_page_menu_admin(&$items, $panel_pages) {
+  // Admin menu
+  $items['admin/panels/panel-page'] = array(
+    'title' => 'Panel pages',
+    'page callback' => 'panels_page_list_page',
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
+    'description' => t('Create and administer panel-pages (complex layout pages with URLs).'),
+  );
+  $items['admin/panels/panel-page/list'] = array(
+    'title' => 'List',
     'weight' => -10,
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+  );
+  $items['admin/panels/panel-page/add'] = array(
+    'title' => 'Add',
+    'page callback' => 'panels_page_add',
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
+    'weight' => -5,
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['admin/panels/panel-page/import'] = array(
+    'title' => 'Import',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('panels_page_import_form'),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
+    'weight' => 0,
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['admin/panels/panel-page/settings'] = array(
+    'title' => 'Settings',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('panels_common_settings_form', 'panels_page'),
+    'file' => '../includes/common.inc',
+    'access arguments' => array('create panel-pages'),
+    'weight' => 10,
+    'type' => MENU_LOCAL_TASK,
+  );
+
+  // Local tasks for all displays
+  $items['admin/panels/panel-page/%panels_page'] = array(
+    'title callback' => 'panels_page_page_title',
+    'title arguments' => array(3),
+    'page callback' => 'panels_page_view_page',
+    'page arguments' => array(3, TRUE),
+    'access arguments' => array('create panel-pages'),
     'type' => MENU_CALLBACK,
   );
 
-  $items[] = array(
-    'path' => $base . '/preview',
-    'title' => t('Preview'),
-    'access' => $access,
-    'callback' => 'panels_page_view_page',
-    'callback arguments' => array($page->name, TRUE),
+  $items['admin/panels/panel-page/%panels_page/preview'] = array(
+    'title' => 'Preview',
     'weight' => -10,
     'type' => MENU_DEFAULT_LOCAL_TASK,
   );
 
-  // Set up for the 'default' display.
-  $items[] = array(
-    'path' => $base . '/edit/layout',
-    'title' => t('Layout'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('panels_page_edit_layout', $page->name),
+  $items['admin/panels/panel-page/%panels_page/export'] = array(
+    'title' => 'Export',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('panels_page_edit_export_form', 3),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
+    'weight' => 0,
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['admin/panels/panel-page/%panels_page/delete'] = array(
+    'title' => 'Delete panel page',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('panels_page_delete_confirm', 3),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
+    'type' => MENU_CALLBACK,
+  );
+
+// Disable and enable functionality has not yet been implemented in panels-5.x-2.0-beta3.
+/*   $items['admin/panels/panel-page/%panels_page/disable'] = array(
+    'page callback' => 'panels_page_disable_page',
+    'page arguments' => array(3),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
+    'weight' => -1,
+    'type' => MENU_CALLBACK,
+  );
+
+  $items['admin/panels/panel-page/%panels_page/enable'] = array(
+    'page callback' => 'panels_page_enable_page',
+    'page arguments' => array(3),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
+    'weight' => -1,
+    'type' => MENU_CALLBACK,
+  ); */
+
+  $items['admin/panels/panel-page/%panels_page/edit/layout'] = array(
+    'title' => 'Layout',
+    'page callback' => 'panels_page_edit_layout',
+    'page arguments' => array(3),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
     'weight' => -9,
     'type' => MENU_LOCAL_TASK,
   );
 
-  $items[] = array(
-    'path' => $base . '/edit/general',
-    'title' => t('Settings'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('panels_page_edit', $page->name),
+  $items['admin/panels/panel-page/%panels_page/edit/general'] = array(
+    'title' => 'Settings',
+    'page callback' => 'panels_page_edit',
+    'page arguments' => array(3),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
     'weight' => -7,
     'type' => MENU_LOCAL_TASK,
   );
 
-  $items[] = array(
-    'path' => $base . '/edit/settings',
-    'title' => t('Layout settings'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('panels_page_edit_layout_settings', $page->name, NULL),
+  $items['admin/panels/panel-page/%panels_page/edit/settings'] = array(
+    'title' => 'Layout settings',
+    'page callback' => 'panels_page_edit_layout_settings',
+    'page arguments' => array(3, NULL),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
     'weight' => -5,
     'type' => MENU_LOCAL_TASK,
   );
 
-  $items[] = array(
-    'path' => $base . '/edit/advanced',
-    'title' => t('Advanced'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('panels_page_edit_advanced', $page->name),
+  $items['admin/panels/panel-page/%panels_page/edit/advanced'] = array(
+    'title' => 'Advanced',
+    'page callback' => 'panels_page_edit_advanced',
+    'page arguments' => array(3),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
     'weight' => -3,
     'type' => MENU_LOCAL_TASK,
   );
 
-  $items[] = array(
-    'path' => $base . '/edit/context',
-    'title' => t('Context'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('panels_page_edit_context', $page->name),
+  $items['admin/panels/panel-page/%panels_page/edit/context'] = array(
+    'title' => 'Context',
+    'page callback' => 'panels_page_edit_context',
+    'page arguments' => array(3),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
     'weight' => -2,
     'type' => MENU_LOCAL_TASK,
   );
 
-  $items[] = array(
-    'path' => $base . '/edit/content',
-    'title' => t('Content'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('panels_page_edit_content', $page->name),
+  $items['admin/panels/panel-page/%panels_page/edit/content'] = array(
+    'title' => 'Content',
+    'page callback' => 'panels_page_edit_content',
+    'page arguments' => array(3),
+    'file' => 'panels_page.admin.inc',
+    'access arguments' => array('create panel-pages'),
     'weight' => -1,
     'type' => MENU_LOCAL_TASK,
   );
 
-  $items[] = array(
-    'path' => $base . '/edit/layout/default',
-    'title' => t('Default'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('panels_page_edit_layout', $page->name),
+  // Local sub-tasks for the 'Default' display 
+  $items['admin/panels/panel-page/%panels_page/edit/layout/default'] = array(
+    'title' => 'Default',
     'weight' => -3,
     'type' => MENU_DEFAULT_LOCAL_TASK,
   );
 
-  $items[] = array(
-    'path' => $base . '/edit/settings/default',
-    'title' => t('Default'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('panels_page_edit_layout_settings', $page->name, NULL),
+  $items['admin/panels/panel-page/%panels_page/edit/settings/default'] = array(
+    'title' => 'Default',
     'weight' => -3,
     'type' => MENU_DEFAULT_LOCAL_TASK,
   );
 
-  $items[] = array(
-    'path' => $base . '/edit/content/default',
-    'title' => t('Default'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('panels_page_edit_content', $page->name),
+  $items['admin/panels/panel-page/%panels_page/edit/content/default'] = array(
+    'title' => 'Default',
     'weight' => -1,
     'type' => MENU_DEFAULT_LOCAL_TASK,
+  );  
+
+/*  $items['admin/panels/panel-page/%panels_page/edit/layout/%'] = array(
+    'title callback' => 'panels_page_page_title',
+    'title arguments' => array(3),
+    'page callback' => 'panels_page_edit_layout',
+    'page arguments' => array(3, 6),
+    'access arguments' => array('create panel-pages'),
+    'weight' => -3,
+    'type' => MENU_LOCAL_TASK,
   );
+*/
+/*  // Get all panels and, if enabled, create menu items.
+  foreach ($panel_pages as $panel_page) {
+    // Local sub-tasks for custom displays
+    if (!empty($panel_page->displays)) {
+      foreach ($panel_page->displays as $display_id => $info) {
+        $items['admin/panels/panel-page/%panels_page/edit/layout/' . $display_id] = array(
+            'title callback' => 'panels_page_page_title',
+            'title arguments' => array(3),
+            'access arguments' => array('create panel-pages'),
+            'weight' => -3,
+            'type' => MENU_LOCAL_TASK,
+        );
+
+        $items['admin/panels/panel-page/%panels_page/edit/settings/' . $display_id] = array(
+            'title' => $info['title'],
+            'access arguments' => array('create panel-pages'),
+            'weight' => -3,
+            'type' => MENU_LOCAL_TASK,
+        );
+
+        $items['admin/panels/panel-page/%panels_page/edit/content/' . $display_id] = array(
+            'title' => $info['title'],
+            'access arguments' => array('create panel-pages'),
+            'weight' => -1,
+            'type' => MENU_LOCAL_TASK,
+        );
+      }
+    }
+  }*/
+}
 
-  if (!empty($page->displays)) {
-    foreach ($page->displays as $display_id => $info) {
-      $items[] = array(
-        'path' => $base . '/edit/layout/' . $display_id,
-        'title' => $info['title'],
-        'access' => $access,
-        'callback' => 'panels_page_passthru',
-        'callback arguments' => array('panels_page_edit_layout', $page->name, $display_id),
-        'weight' => -3,
-        'type' => MENU_LOCAL_TASK,
-      );
-
-      $items[] = array(
-        'path' => $base . '/edit/settings/' . $display_id,
-        'title' => $info['title'],
-        'access' => $access,
-        'callback' => 'panels_page_passthru',
-        'callback arguments' => array('panels_page_edit_layout_settings', $page->name, $display_id),
-        'weight' => -3,
-        'type' => MENU_LOCAL_TASK,
-      );
-
-      $items[] = array(
-        'path' => $base . '/edit/content/' . $display_id,
-        'title' => $info['title'],
-        'access' => $access,
-        'callback' => 'panels_page_passthru',
-        'callback arguments' => array('panels_page_edit_content', $page->name, $display_id),
-        'weight' => -1,
-        'type' => MENU_LOCAL_TASK,
-      );
+function _panels_page_menu_panel(&$items, $panel_pages) {
+  foreach ($panel_pages as $panel_page) {
+    // Only create menu items based on the path if it's not a variable path.
+    if (strpos($panel_page->path, '%') === FALSE) {
+      _panels_page_create_menu_item($items, $panel_page, $panel_page->path, array($panel_page->name, FALSE));
+      // DEBUG: Above is now creating only the basic menu item, not the admin items.
     }
   }
 
-  $items[] = array(
-    'path' => $base . '/export',
-    'title' => t('Export'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('drupal_get_form', 'panels_page_edit_export', $page->name),
-    'weight' => 0,
-    'type' => MENU_LOCAL_TASK,
-  );
-  $items[] = array(
-    'path' => $base . '/delete',
-    'title' => t('Delete panel page'),
-    'access' => $access,
-    'callback' => 'panels_page_passthru',
-    'callback arguments' => array('drupal_get_form', 'panels_page_delete_confirm', $page->name),
-    'type' => MENU_CALLBACK,
-  );
+  // Look for panels with variable arguments.
+  // Build an array of $urls because 'real' URLs will take precedence over
+  // argument filled URLs
+  $urls = array();
+  foreach ($panel_pages as $panel_page) {
+    $url[$panel_page->path] = TRUE;
+  }
+
+  $plugins_loaded = FALSE;
+  foreach ($panel_pages as $panel_page) {
+    if (strpos($panel_page->path, '%') !== FALSE) {
+      $path = explode('/', $panel_page->path);
+      $match = TRUE;
+      foreach ($path as $id => $chunk) {
+        if ($chunk != '%' && $chunk != arg($id)) {
+          $match = FALSE;
+          break;
+        }
+      }
+      // It's a MATCH! Construct the URL
+      if ($match) {
+        $args = array($panel_page, FALSE);
+        reset($panel_page->arguments);
+        foreach ($path as $id => $chunk) {
+          if ($chunk != '%') {
+            continue;
+          }
+          // For arguments that are embedded in the URL, we require the
+          // argument handler to return a context, if there is an argument handler.
+          $argument = current($panel_page->arguments);
+          if ($argument) {
+            // Try to avoid loading the plugins code unless necessary.
+            if (!$plugins_loaded) {
+              panels_load_include('plugins');
+              $plugins_loaded = TRUE;
+            }
+            $context = panels_argument_get_context($argument, arg($id));
+            if (!$context) {
+              break;
+            }
+            $panel_page->context[panels_argument_context_id($argument)] = $context;
+          }
+          $path[$id] = arg($id);
+          $args[] = arg($id);
+          next($panel_page->arguments);
+        }
+        _panels_page_create_menu_item($items, $panel_page, implode('/', $path), $args);
+        // DEBUG: Above is now creating only the basic menu item, not the admin items.
+      }
+    }
+  }
 }
-
 /**
  * Create a menu item for a panel page.
  */
@@ -384,7 +355,7 @@
   if ($type == MENU_LOCAL_TASK || $type == MENU_DEFAULT_LOCAL_TASK) {
     $weight = $panel_page->menu_tab_weight;
   }
-  $items[] = _panels_page_menu_item($path, $title, $panel_page, $args, $access, $type, $weight);
+  $items[$path] = _panels_page_menu_item($title, $panel_page, $args, $access, $type, $weight);
 
   if ($type == MENU_DEFAULT_LOCAL_TASK && dirname($path) && dirname($path) != '.') {
     switch ($panel_page->menu_tab_default_parent_type) {
@@ -402,20 +373,20 @@
     if ($parent_type) {
       $title = filter_xss_admin(panels_page_get_title($panel_page, 'menu-parent'));
       $weight = $panel_page->menu_parent_tab_weight;
-      $items[] = _panels_page_menu_item(dirname($path), $title, $panel_page, $args, $access, $parent_type, $weight);
+      $items[dirname($path)] = _panels_page_menu_item($title, $panel_page, $args, $access, $parent_type, $weight);
+      dprint_r($items[dirname($path)]);
     }
   }
 }
-
 /**
  * Helper function to create a menu item for a panel.
  */
-function _panels_page_menu_item($path, $title, $panel_page, $args, $access, $type, $weight = NULL) {
-  $retval = array('path' => $path,
+function _panels_page_menu_item($title, $panel_page, $args, $access, $type, $weight = NULL) {
+  $retval = array(
     'title' => $title,
-    'callback' => 'panels_page_view_page',
-    'callback arguments' => $args,
-    'access' => user_access('access content') && $access,
+    'page callback' => 'panels_page_view_page',
+    'page arguments' => $args,
+    'access callback' => user_access('access content') && $access,
     'type' => $type,
   );
   if ($weight !== NULL) {
@@ -425,6 +396,13 @@
 }
 
 /**
+  * Title callback
+  */
+function panels_page_page_title($page) {
+  return $page->title;
+}
+
+/**
  * Determine what menu type a panel needs to use.
  */
 function _panels_page_menu_type($panel_page) {
@@ -561,26 +539,6 @@
 // ---------------------------------------------------------------------------
 // panel page administrative pages
 
-/**
- * Settings for panel pages
- */
-function panels_page_settings() {
-  panels_load_include('common');
-  return drupal_get_form('panels_common_settings', 'panels_page');
-}
-
-/**
- * Pass-through to admin.inc
- */
-function panels_page_passthru() {
-  $args = func_get_args();
-  $callback = array_shift($args);
-
-  panels_load_include('panels_page.admin', 'panels_page/');
-  panels_load_include('plugins');
-  return call_user_func_array($callback, $args);
-}
-
 function panels_move_menu_tabs($path, $tab) {
   global $_menu;
 
@@ -630,9 +588,6 @@
  * Page callback to view a panel page.
  */
 function panels_page_view_page($panel_page, $admin) {
-  if (!is_object($panel_page)) {
-    $panel_page = panels_page_load($panel_page);
-  }
   if (!$panel_page) {
     return drupal_not_found();
   }
@@ -647,7 +602,7 @@
   if ($admin) {
     // Display an admin form to make it easy to set up arguments.
     panels_load_include('panels_page.admin', 'panels_page/');
-    $output .= drupal_get_form('panels_page_admin_view', $panel_page, $args);
+    $output .= drupal_get_form('panels_page_admin_view_form', $panel_page, $args);
   }
   else {
     // This piece of code goes deep into the menu system, finds the
@@ -738,9 +693,8 @@
 /**
  * Load a display based upon information from the $displays list.
  */
-function panels_page_fetch_display(&$panel_page, $id = NULL) {
-  $did = NULL;
-  if (empty($id)) {
+function panels_page_fetch_display(&$panel_page, $did = NULL) {
+  if (empty($did)) {
     // If empty, use the default display.
     if (empty($panel_page->display)) {
       // Load it if not already loaded
@@ -753,7 +707,7 @@
   }
   else {
     // Otherwise, fetch from our alternative displays.
-    $display = _panels_page_fetch_display($panel_page, $id);
+    $display = _panels_page_fetch_display($panel_page, $did);
   }
 
   $display->owner = $panel_page;
@@ -764,8 +718,8 @@
 /**
  * Fetch a display from a panel pages alternative list of displays
  */
-function _panels_page_fetch_display(&$panel_page, $id) {
-  $info = $panel_page->displays[$id];
+function _panels_page_fetch_display(&$panel_page, $did) {
+  $info = $panel_page->displays[$did];
   if ($display = _panels_fetch_display_from_info($info)) {
     return $display;
   }
@@ -900,6 +854,7 @@
       $where = 'pid = %d';
     }
     $page = db_fetch_object(db_query("SELECT * FROM {panels_page} WHERE $where", $pid));
+	
     if (!$page) {
       $defaults = panels_page_default_panels();
       if (isset($defaults[$pid])) {
@@ -925,33 +880,6 @@
 }
 
 /**
- * A list of the fields used in the panel_page table.
- */
-function panels_page_fields() {
-  return array(
-    "name" => "'%s'",
-    "title" => "'%s'",
-    "arguments" => "'%s'",
-    "displays" => "'%s'",
-    "contexts" => "'%s'",
-    "relationships" => "'%s'",
-    "access" => "'%s'",
-    "path" => "'%s'",
-    "css_id" => "'%s'",
-    "css" => "'%s'",
-    "no_blocks" => "%d",
-    "menu" => "%d",
-    "menu_tab" => "%d",
-    "menu_tab_weight" => "%d",
-    "menu_title" => "'%s'",
-    "menu_tab_default" => "%d",
-    "menu_tab_default_parent_type" => "'%s'",
-    "menu_parent_title" => "'%s'",
-    "menu_parent_tab_weight" => "%d",
-  );
-}
-
-/**
  * Sanitize a panel prior to saving it.
  */
 function panels_page_sanitize($page) {
@@ -966,14 +894,21 @@
 
 /**
  * Save a panel page.
+ * 
+ * @param $panel_page
+ *   The panel page object to be saved.
+ * @return
+ *   The performed database query on the panels_page table,
+ *   or FALSE if either of the queries was not successful.
  */
 function panels_page_save($panel_page) {
+  kprint_r($panel_page);
   // Save the display if one was given to us.
   if (!empty($panel_page->display)) {
-    $display = panels_save_display($panel_page->display);
+    panels_save_display($panel_page->display);
   }
-  // Ensure empty values get translated correctly. Also make sure we don't
-  // mess up the original.
+  // Ensure empty values get translated correctly.
+  // Also make sure we don't mess up the original.
   $page = drupal_clone(panels_page_sanitize($panel_page));
 
   // Check to see if we need to save any imported displays.
@@ -992,56 +927,39 @@
   $page->contexts = serialize($page->contexts);
   $page->relationships = serialize($page->relationships);
 
-  // Create strings for our query from the list of fields.
-  $fields = panels_page_fields();
-  foreach ($fields as $field => $value) {
-    if (isset($page->$field)) {
-      $f[] = $field;
-      $q[] = $value;
-      $v[] = $page->$field;
-    }
+  if (empty($page->name)) {
+    $page->name = 'panel_page_' . $page->pid;
   }
 
   if ($page->pid && $page->pid != 'new') {
-    if (empty($page->name)) {
-      $page->name = 'panel_page_' . $page->pid;
-    }
-    $query = '';
-    foreach ($f as $id => $field) {
-      if ($query) {
-        $query .= ', ';
-      }
-      $query .= "$f[$id] = " . $q[$id];
-    }
-
-    $v[] = $page->pid;
-    db_query("UPDATE {panels_page} SET $query WHERE pid = %d", $v);
+    drupal_write_record('panels_page', $page, 'pid');
   }
   else {
-    $page->pid = db_next_id("{panels_page}_pid");
-    // Tack our pid and did onto the query. These aren't listed as 'fields' because
-    // they can't be updated; once set they are permanent.
-    $v[] = $page->pid;
-    $v[] = $display->did;
-
-    if (empty($page->name)) {
-      $page->name = 'panel_page_' . $page->pid;
-    }
-    // Yes, this is kind of long but it's a lot easier to match up values.
-    db_query("INSERT INTO {panels_page} ( " . implode(', ', $f) . ", pid, did) VALUES (" . implode(', ', $q) . ", %d, %d)", $v);
+    $page->did = $page->display->did;
+    drupal_write_record('panels_page', $page);
   }
-
+  
   menu_rebuild();
-  return $page->pid;
+  return $page;
 }
 
 /**
  * Delete a panel page and its associated display.
+ * 
+ * @param $panel_page
+ *   A panel page object.
+ * @return
+ *   The performed database query on the panels_page table,
+ *   or FALSE if either of the queries was not successful.
  */
 function panels_page_delete($panel_page) {
-  db_query("DELETE FROM {panels_page} WHERE pid = %d", $panel_page->pid);
-  menu_rebuild();
-  return panels_delete_display($panel_page->did);
+  if ($success = db_query("DELETE FROM {panels_page} WHERE pid = %d", $panel_page->pid)) {
+    menu_rebuild();
+    if (panels_delete_display($panel_page->did)) {
+      return $success;
+    }
+  }
+  return FALSE;
 }
 
 /**
@@ -1049,30 +967,28 @@
  * can be used directly in panels_page_save().
  */
 function panels_page_export($panel_page, $prefix = '') {
-  $output = '';
-  $fields = panels_page_fields();
-  $output .= $prefix . '$page = new stdClass()' . ";\n";
-  $output .= $prefix . '$page->pid = \'new\'' . ";\n";
-  foreach ($fields as $field => $q) {
-    if ($field == 'displays') {
-      continue;
-    }
-
-    $output .= $prefix . '  $page->' . $field . ' = ' . panels_var_export($panel_page->$field, '  ') . ";\n";
+  $output = $prefix . "\$page = new stdClass();\n";
+  $output .= $prefix . "\$page->pid = 'new';\n";
+  
+  // Export panel page fields except for displays.
+  $fields = array_diff(drupal_schema_fields_sql('panels_page'), array('pid', 'did', 'displays'));
+  foreach ($fields as $field) {
+    $output .= $prefix . "  \$page->$field  = " . panels_var_export($panel_page->$field, '  ') . ";\n";
   }
-  // Export the primary display
+
+  // Export the primary display.
   $display = !empty($panel_page->display) ? $panel_page->display : panels_load_display($panel_page->did);
   $output .= panels_export_display($display, $prefix);
-  $output .= $prefix . '$page->display = $display' . ";\n";
+  $output .= $prefix . "\$page->display = \$display;\n";
 
-  // Export all secondary displays
-  $output .= $prefix . '$page->displays = array()' . ";\n";
+  // Export all secondary displays.
+  $output .= $prefix . "\$page->displays = array();\n";
   foreach ($panel_page->displays as $did => $info) {
-    $output .= $prefix . '  $page->displays[\'' . $did . "']['title'] = '" . check_plain($info['title']) . "';\n";
-    $output .= $prefix . '  $page->displays[\'' . $did . "']['argument_id'] = '" . check_plain($info['argument_id']) . "';\n";
+    $output .= $prefix . "  \$page->displays['$did']['title'] = " . check_plain($info['title']) . "';\n";
+    $output .= $prefix . "  \$page->displays['$did']['argument_id'] = " . check_plain($info['argument_id']) . "';\n";
     $display = !empty($info['display']) ? $info['display'] : panels_load_display($info['did']);
     $output .= panels_export_display($display, $prefix . '    ');
-    $output .= $prefix . '  $page->displays[\'' . $did . "']['display'] =  \$display;\n";
+    $output .= $prefix . "  \$page->displays['$did']['display'] = \$display;\n";
   }
   return $output;
 }
Index: panels/panels_page/panels_page.info
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/panels_page/Attic/panels_page.info,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 panels_page.info
--- panels/panels_page/panels_page.info	29 Aug 2007 22:02:04 -0000	1.1.2.1
+++ panels/panels_page/panels_page.info	30 Apr 2008 10:19:21 -0000
@@ -2,5 +2,6 @@
 name = Panel pages
 description = Create pages that are divided into areas of the page.
 package = "Panels"
-dependencies = panels
+dependencies[] = panels
+core = 6.x
 
Index: panels/includes/display_edit.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/includes/Attic/display_edit.inc,v
retrieving revision 1.1.2.23
diff -u -r1.1.2.23 display_edit.inc
--- panels/includes/display_edit.inc	24 Jan 2008 17:51:12 -0000	1.1.2.23
+++ panels/includes/display_edit.inc	30 Apr 2008 10:19:20 -0000
@@ -28,15 +28,12 @@
   // Break out the form pieces so we can return the new $display upon
   // successful submit.
 
-  $form_id = 'panels_edit_display';
-  $form = drupal_retrieve_form($form_id, $display, $destination);
-
-  if ($result = drupal_process_form($form_id, $form)) {
-    // successful submit
-    return $result;
-  }
-
-  $output = drupal_render_form($form_id, $form);
+  $form_id = 'panels_edit_display_form';
+  // $form = drupal_retrieve_form($form_id, $display, $destination);
+  // drupal_prepare_form($form_id, $form, $form_state);
+  // drupal_process_form($form_id, $form, $form_state);
+  // $output = drupal_render_form($form_id, $form);
+  $output = drupal_get_form($form_id, $display, $destination);
   $output .= theme('panels_hidden');
   return $output;
 }
@@ -44,31 +41,29 @@
 /**
  * Form definition for the panels display editor
  */
-function panels_edit_display($display, $destination) {
+function panels_edit_display_form(&$form_state, $display, $destination) {
   $form['did'] = array(
     '#type' => 'hidden',
     '#value' => $display->did,
     '#id' => 'panel-did',
   );
-
   $form['op'] = array(
     '#type' => 'hidden',
     '#id' => 'panel-op',
   );
-
   $form['panels_display'] = array(
     '#type' => 'value',
     '#value' => $display
   );
 
   if (!empty($destination)) {
-    $form['destination'] = array(
+    $form['redirect'] = array(
       '#type' => 'value',
       '#value' => $destination
     );
   }
   else {
-    $form['#redirect'] = FALSE;
+    $form['redirect'] = FALSE;
   }
 
   $form['explanation'] = array(
@@ -140,44 +135,20 @@
     '#id' => 'panels-cache-settings',
   );
 
-  if ($submit) {
+  if ($destination) {
     // The caller wants their own submit.
-    $form['#submit'] = array($submit => array());
+    $form['#submit'] = array($destination => array());
   }
   return $form;
 }
 
-function theme_panels_edit_display($form) {
-  _panels_js_files();
-  $display = $form['panels_display']['#value'];
-  $layout = panels_get_layout($display->layout);
-  $layout_panels = panels_get_panels($layout, $display);
-  $save_buttons = drupal_render($form['submit']) . drupal_render($form['cancel']);
-
-  foreach ($layout_panels as $panel_id => $title) {
-    foreach ((array) $display->panels[$panel_id] as $pid) {
-      $pane = $display->content[$pid];
-      $left_buttons = NULL;
-      $buttons = !empty($form['button'][$pid]['cache']) ? drupal_render($form['button'][$pid]['cache']) : '';
-      $buttons .= drupal_render($form['button'][$pid]['configure']);
-      $buttons .= drupal_render($form['button'][$pid]['delete']);
-      $content[$pane->panel] .= panels_show_pane($display, $pane, $left_buttons, $buttons);
-    }
-    $content[$panel_id] = theme('panels_panel_dnd', $content[$panel_id], $panel_id, $title, drupal_render($form['panels'][$panel_id]['add']));
-  }
-  $output .= drupal_render($form);
-  $output .= theme('panels_dnd', panels_render_layout($layout, $content, '', $display->layout_settings));
-  $output .= $save_buttons;
-  return $output;
-}
-
-function panels_edit_display_submit($form_id, $form_values) {
-  $display = $form_values['panels_display'];
-  if ($form_values['op'] == t('Save')) {
+function panels_edit_display_form_submit($form, &$form_state) {
+  $display = $form_state['values']['panels_display'];
+  if ($form_state['clicked_button']['#id'] == 'panels-dnd-save') {
     $old_content = $display->content;
     $display->content = array();
 
-    foreach ($form_values['panel']['pane'] as $panel_id => $panes) {
+    foreach ($form_state['values']['panel']['pane'] as $panel_id => $panes) {
       $display->panels[$panel_id] = array();
       if ($panes) {
         $pids = explode(',', $panes);
@@ -195,156 +166,117 @@
   }
 
   panels_cache_clear($display->did);
-  if (empty($form_values['destination'])) {
-    return $display;
+  if (empty($form_state['redirect'])) {
+    $form_state['redirect'] = $display;
   }
 }
 
-function _panels_edit_layout($display, $finish, $destination = NULL) {
-  // Break out the form pieces so we can return the new $display upon
-  // successful submit.
-  $form_id = 'panels_choose_layout';
-  $form = drupal_retrieve_form($form_id, $display, $finish, $destination);
+function theme_panels_edit_display_form($form) {
+  _panels_js_files();
+  $display = $form['panels_display']['#value'];
+  $layout = panels_get_layout($display->layout);
+  $layout_panels = panels_get_panels($layout, $display);
+  $save_buttons = drupal_render($form['submit']) . drupal_render($form['cancel']);
 
-  if ($result = drupal_process_form($form_id, $form)) {
-    // successful submit
-    return $result;
+  foreach ($layout_panels as $panel_id => $title) {
+    foreach ((array) $display->panels[$panel_id] as $pid) {
+      $pane = $display->content[$pid];
+      $left_buttons = NULL;
+      $buttons = !empty($form['button'][$pid]['cache']) ? drupal_render($form['button'][$pid]['cache']) : '';
+      $buttons .= drupal_render($form['button'][$pid]['configure']);
+      $buttons .= drupal_render($form['button'][$pid]['delete']);
+      $content[$pane->panel] .= panels_show_pane($display, $pane, $left_buttons, $buttons);
+    }
+    $content[$panel_id] = theme('panels_panel_dnd', $content[$panel_id], $panel_id, $title, drupal_render($form['panels'][$panel_id]['add']));
   }
-  $output = drupal_render_form($form_id, $form);
+
+  $output .= drupal_render($form);
+  $output .= theme('panels_dnd', panels_render_layout($layout, $content, '', $display->layout_settings));
+  $output .= $save_buttons;
   return $output;
 }
 
+function _panels_edit_layout(&$display, $finish, $destination = NULL) {
+  // Break out the form pieces so we can return the new $display upon
+  // successful submit.
+  return drupal_get_form('panels_edit_layout_form', $display, $destination);
+}
+
 /**
- * Form to change the layout of a display.
+ * Form constructor: change the layout of a display.
  */
-function panels_choose_layout($display, $finish, $destination) {
-  $layouts = panels_get_layouts();
-
-  foreach ($layouts as $id => $layout) {
-    $options[$id] = panels_print_layout_icon($id, $layout, check_plain($layout['title']));
+function panels_edit_layout_form(&$form_state, $display, $destination) {
+  $form = array();
+  // If there is no content, this is a one-step form.
+  if (!$display->content) {
+    $form = _panels_edit_layout_form_choose($display, TRUE);
+    $form['display'] = array('#type' => 'value', '#value' => $display);
   }
+  else {
+    // Step one of a two-step form
+    if (empty($form_state['storage'])) {
+      $form = _panels_edit_layout_form_choose($display);
+    }
+    // Step two of a two-step form
+    else {
+      $form = _panels_edit_layout_form_change($display, $form_state['storage']['new_layout']);
+      $form['display'] = array('#type' => 'value', '#value' => $display);
+    }
+  }
+  return $form;
+}
 
-  drupal_add_js(panels_get_path('js/layout.js'));
-  $form['layout'] = array(
+function _panels_edit_layout_form_choose($display, $last_step = FALSE) {
+  foreach (panels_get_layouts() as $id => $layout) {
+    $options[$id] = panels_print_layout_icon($layout, check_plain($layout['title']));
+  }
+  $form['new_layout'] = array(
     '#type' => 'radios',
     '#title' => t('Choose layout'),
     '#options' => $options,
     '#default_value' => $display->layout,
   );
-
-  $form['clearer'] = array(
-    // TODO: FIx this to use clear-block instead
-    '#value' => '<div style="clear: both;"></div>',
-  );
-
-  $form['variables'] = array(
-    '#type' => 'value',
-    '#value' => array($display, $finish, $destination),
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => $last_step ? t('Save') : t('Next'),
   );
-
-  if (empty($destination)) {
-    $form['#redirect'] = FALSE;
-  }
-
-  if ($_POST['op'] && $_POST['op'] != t('Back') && $display->content) {
-    $form['#post'] = $_POST;
-    $form = form_builder('panels_choose_layout', $form);
-    unset($form['#post']);
-    $form['layout']['#type'] = 'hidden';
-    panels_change_layout($form, $display, $form['layout']['#value']);
-  }
-
-  if (($_POST['op'] && $_POST['op'] != t('Back')) || !$display->content) {
-    $form['submit'] = array(
-      '#type' => 'submit',
-      '#value' => $finish,
-    );
-  }
-  else {
-    $form['submit'] = array(
-      '#type' => 'submit',
-      '#value' => t('Next'),
-    );
-  }
-
-  $form['#token'] = FALSE; // no token please
+  $form['#theme'] = 'panels_edit_layout_form_choose';
   return $form;
 }
 
-function panels_choose_layout_submit($form_id, $form_values) {
-  list($display, $finish, $destination) = $form_values['variables'];
-  $new_layout_id = $form_values['layout'];
-
-  if ($form_values['op'] == $finish) {
-    if (!empty($form_values['old'])) {
-      foreach ($form_values['old'] as $id => $new_id) {
-        $content[$new_id] = array_merge((array) $content[$new_id], $display->panels[$id]);
-        foreach($content[$new_id] as $pid) {
-          $display->content[$pid]->panel = $new_id;
-        }
-      }
-
-      $display->panels = $content;
-    }
-
-    $display->layout = $new_layout_id;
-
-    // save it back to our session.
-    panels_save_display($display);
-    if (empty($destination)) {
-      return $display;
-    }
-
-    return $destination;
-  }
-
-  return FALSE;
-}
-
-function panels_change_layout(&$form, $display, $new_layout_id) {
+function _panels_edit_layout_form_change($display, $new_layout_id) {
+  $old_layout_id = $display->layout;
+  $old_layout = panels_get_layout($old_layout_id);
+  $old_layout_panels = panels_get_panels($old_layout, $display);
+  
   $new_layout = panels_get_layout($new_layout_id);
   $new_layout_panels = panels_get_panels($new_layout, $display);
 
-  $options = $new_layout_panels;
-  $keys = array_keys($options);
-  $default = $options[0];
-
-  $old_layout = panels_get_layout($display->layout);
-
   $form['container'] = array(
     '#prefix' => '<div class="change-layout-display">',
     '#suffix' => '</div>',
   );
-
   $form['container']['old_layout'] = array(
-    '#value' => panels_print_layout_icon($display->layout, $old_layout, check_plain($old_layout['title'])),
-  );
-
-  $form['container']['right_arrow'] = array(
-    '#value' => theme('image', drupal_get_path('module', 'panels') . '/images/go-right.png'),
+    '#type' => 'value',
+    '#value' => $old_layout_id,
   );
   $form['container']['new_layout'] = array(
-    '#value' => panels_print_layout_icon($new_layout_id, $new_layout, check_plain($new_layout['title'])),
-  );
-
-  $form['container-clearer'] = array(
-    // TODO: FIx this ot use clear-block instead
-    '#value' => '<div style="clear: both;"></div>',
+    '#type' => 'value',
+    '#value' => $new_layout_id,
   );
 
-  $form['old'] = array(
+  $form['move_content'] = array(
     '#tree' => true,
     '#prefix' => '<div class="panels-layout-list">',
     '#suffix' => '</div>',
   );
 
-  $old_layout_panels = panels_get_panels($old_layout, $display);
-  foreach ($display->panels as $id => $content) {
-    $form['old'][$id] = array(
+  foreach ($display->panels as $area => $content) {
+    $form['move_content'][$area] = array(
       '#type' => 'select',
-      '#title' => t('Move content in @layout to', array('@layout' => $old_layout_panels[$id])),
-      '#options' => $options,
-      '#default_value' => array_key_exists($id, $options) ? $id : $default,
+      '#title' => t('Move content in %area to', array('%area' => $old_layout_panels[$area])),
+      '#options' => $new_layout_panels,
+      '#default_value' => array_key_exists($area, $new_layout_panels) ? $area : $new_layout_panels[0],
     );
   }
 
@@ -352,34 +284,116 @@
     '#type' => 'submit',
     '#value' => t('Back'),
   );
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+  );
+
+  //  $form['#token'] = FALSE; // no token please
+  // $form['#theme'] = 'panels_edit_layout_form_change';
   return $form;
 }
 
+function panels_edit_layout_form_validate($form, &$form_state) {
+}
+
+function panels_edit_layout_form_submit($form, &$form_state) {
+  kprint_r($form_state);
+  switch ($form_state['clicked_button']['#value']) {
+    case t('Back'):
+      $form_state['storage'] = NULL;
+      $form_state['rebuild'] = TRUE;
+      break;
+    case t('Next'):
+      dsm($form_state['values']['new_layout']);
+      $form_state['storage']['new_layout'] = $form_state['values']['new_layout'];
+      break;
+    case t('Save'):
+      if ($areas = $form_state['values']['move_content']) {
+        if (!empty($areas)) {
+          $panels = array();
+          foreach ($areas as $old_area => $new_area) {
+            $panels[$new_area] = array_merge((array) $panels[$new_area], $form_state['values']['display']->panels[$old_area]);
+            foreach($panels[$new_area] as $pid) {
+              $form_state['values']['display']->content[$pid]->panel = $new_id;
+            }
+          }
+          $form_state['values']['display']->panels = $content;
+        }
+      }
+      $form_state['values']['display']->layout = $form_state['values']['new_layout'];
+      // save it back to our session.
+      if (panels_save_display($form_state['values']['display'])) {
+        drupal_set_message(t('The layout has been changed to @layout.', array('@layout' => $form_state['values']['new_layout'])));
+      }
+      $form_state['storage'] = NULL;
+      $form_state['redirect'] = FALSE;
+  }
+}
+
+function theme_panels_edit_layout_form_choose($form) {
+  drupal_add_js(panels_get_path('js/layout.js'));
+ 
+  $output = '';
+  $output .= drupal_render($form['new_layout']);
+  $output .= '<div style="clear: both;"></div>';
+  $output .= drupal_render($form['submit']);
+  $output .= drupal_render($form);
+  return $output;
+}
+
+function theme_panels_edit_layout_form_change($form) {
+/*  $output = '<div class="change-layout-display">';
+
+  $container = array();
+  $container['new_layout'] = array(
+    '#value' => panels_print_layout_icon($old_layout, check_plain($old_layout['title'])),
+  );
+  $container['right_arrow'] = array(
+    '#value' => theme('image', panels_get_path('images/go-right.png')),
+  );
+  $container['new_layout'] = array(
+    '#value' => panels_print_layout_icon($new_layout, check_plain($new_layout['title'])),
+  );
+  
+  $output .= drupal_render($form['container']);
+  
+  $output .= '</div><div style="clear: both;"></div>';
+
+  $output .= drupal_render($form['move_content']);
+
+  $output .= drupal_render($form['back']);
+  $output .= drupal_render($form['submit']);
+  $output .= drupal_render($form);
+  
+  return $output;
+  return drupal_render($form);*/
+}
+
 function _panels_edit_layout_settings($display, $finish, $destination = NULL) {
   // Break out the form pieces so we can return the new $display upon
   // successful submit.
   $form_id = 'panels_edit_layout_settings_form';
-  $form = drupal_retrieve_form($form_id, $display, $finish, $destination);
-
-  if ($result = drupal_process_form($form_id, $form)) {
-    // successful submit
-    return $result;
-  }
-  $output = drupal_render_form($form_id, $form);
-  return $output;
+  // $form = drupal_retrieve_form($form_id, $display, $finish, $destination);
+  // drupal_prepare_form($form_id, $form, $form_state);
+  // drupal_process_form($form_id, $form, $form_state);
+  // return drupal_render_form($form_id, $form);
+  return drupal_get_form($form_id, $display, $finish, $destination);
 }
 
 /**
  * Form to change the layout of a display.
  */
-function panels_edit_layout_settings_form($display, $finish, $destination) {
+function panels_edit_layout_settings_form($form_state, $display, $finish, $destination) {
+  
+  // Some layouts have their own layout specific settings.
   $layout = panels_get_layout($display->layout);
   if (!empty($layout['settings form']) && function_exists($layout['settings form'])) {
     $form['layout_settings'] = $layout['settings form']($display, $layout, $display->layout_settings);
+    $form['layout_settings']['#tree'] = TRUE;
   }
 
-  $form['layout_settings']['#tree'] = TRUE;
-
+  // Always show general Panel settings. 
   $form += panels_panel_settings($display);
 
   $form['variables'] = array(
@@ -387,10 +401,6 @@
     '#value' => array($display, $finish, $destination),
   );
 
-  if (empty($destination)) {
-    $form['#redirect'] = FALSE;
-  }
-
   $form['layout'] = array(
     '#type' => 'value',
     '#value' => $layout,
@@ -404,48 +414,47 @@
       '#value' => t('Save'),
     );
   }
-
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => $finish,
   );
 
-
   return $form;
 }
 
-function panels_edit_layout_settings_form_validate($form_id, $form_values, $form) {
-  list($display, $finish, $destination) = $form_values['variables'];
-  panels_panel_settings_validate($form_id, $form_values, $form);
-  $layout = $form_values['layout'];
+function panels_edit_layout_settings_form_validate($form, $form_state) {
+  list($display, $finish, $destination) = $form_state['values']['variables'];
+  panels_panel_settings_validate($form, $form_state);
+  $layout = $form_state['values']['layout'];
   if (!empty($layout['settings validate']) && function_exists($layout['settings validate'])) {
-    $layout['settings validate']($form_values['layout_settings'], $form['layout_settings'], $display, $layout, $display->layout_settings);
+    $layout['settings validate']($form_state['values']['layout_settings'], $form['layout_settings'], $display, $layout, $display->layout_settings);
   }
 }
 
-function panels_edit_layout_settings_form_submit($form_id, $form_values) {
-  list($display, $finish, $destination) = $form_values['variables'];
-  panels_panel_settings_submit($form_id, $form_values);
+function panels_edit_layout_settings_form_submit($form, $form_state) {
+  list($display, $finish, $destination) = $form_state['values']['variables'];
+  panels_panel_settings_submit($form, $form_state);
 
-  $layout = $form_values['layout'];
+  $layout = $form_state['values']['layout'];
   if (!empty($layout['settings submit']) && function_exists($layout['settings submit'])) {
-    $layout['settings submit']($form_values['layout_settings'], $display, $layout, $display->layout_settings);
+    $layout['settings submit']($form_state['values']['layout_settings'], $display, $layout, $display->layout_settings);
   }
-
-  if ($form_values['op'] == $finish || $form_values['op'] == t('Save')) {
-    $display->layout_settings = $form_values['layout_settings'];
-    $display->panel_settings = $form_values['panel_settings'];
+  if (empty($destination)) {
+    $form['redirect'] = FALSE;
+  }
+  if ($form_state['clicked_button'] == $finish || $form_state['clicked_button'] == t('Save')) {
+    $display->layout_settings = $form_state['values']['layout_settings'];
+    $display->panel_settings = $form_state['values']['panel_settings'];
 
     panels_save_display($display);
     drupal_set_message("Your layout settings have been saved.");
-    if ($form_values['op'] != $finish) {
+    if ($form_state['clicked_button'] != $finish) {
       // This forces us to come back here if they hit Save.
-      $_REQUEST['destination'] = $_GET['q'];
+      $form_state['redirect'] = $display;
     }
-    if (empty($destination)) {
-      return $display;
+    else {
+      $form_state['redirect'] = empty($destination) ? $display : $destination;
     }
-    return $destination;
   }
 }
 
@@ -584,7 +593,10 @@
         }
         $output = '<div class="content-type-button">';
         $link_text = theme('image', $path . '/' . $icon, $description, $description);
-        $output .= l($link_text, 'javascript: void()', array('class' => 'panels-modal-add-config', 'id' => $id . '-' . $panel_id . '-' . $content_id), NULL, NULL, NULL, TRUE);
+        $output .= l($link_text, 'javascript: void()', array(
+          'attributes' => array('class' => 'panels-modal-add-config', 'id' => $id . '-' . $panel_id . '-' . $content_id),
+          'html' => true
+        ));
         $output .= "<div>$title</div>";
         $output .= '</div>';
         if (!isset($categories[$category])) {
@@ -638,7 +650,7 @@
   panels_ajax_render($output);
 }
 
-function panels_add_content_config_form($display, $content_type_id = NULL, $subtype = NULL, $conf = NULL, $panel_id = NULL, $title = NULL) {
+function panels_add_content_config_form($form_state, $display, $content_type_id = NULL, $subtype = NULL, $conf = NULL, $panel_id = NULL, $title = NULL) {
   if (empty($content_type_id)) {
     $cache = panels_cache_get($display->did);
     if (isset($cache->add_config)) {
@@ -705,11 +717,11 @@
   return $form;
 }
 
-function panels_add_content_config_form_validate($form_id, $form_values, $form) {
-  panels_ct_validate_add_form($form_values['type'], $form['configuration'], $form_values['configuration']);
+function panels_add_content_config_form_validate($form, $form_state) {
+  panels_ct_validate_add_form($form_state['values']['type'], $form['configuration'], $form_state['values']['configuration']);
 }
 
-function panels_add_content_config_form_submit($form_id, $form) {
+function panels_add_content_config_form_submit($form, $form_state) {
   $cache = panels_cache_get($form['did']);
 
   // keep an incrementing counter, add the data to the display.
@@ -747,7 +759,7 @@
   $return->output = panels_show_pane($cache->display, $cache->display->content[$form['pid']], NULL, drupal_render($buttons));
 
   panels_set('return', $return);
-  return FALSE;
+  $form_state['redirect'] = FALSE;
 }
 
 /**
@@ -762,7 +774,7 @@
   panels_ajax_render($output);
 }
 
-function panels_edit_pane_config_form($display, $pid = NULL) {
+function panels_edit_pane_config_form($form_state, $display, $pid = NULL) {
   $cache = panels_cache_get($display->did);
   if ($pid === NULL) {
     if (isset($cache->pid)) {
@@ -835,11 +847,11 @@
   return $form;
 }
 
-function panels_edit_pane_config_form_validate($form_id, $form_values, $form) {
-  panels_ct_validate_edit_form($form_values['type'], $form['configuration'], $form_values['configuration']);
+function panels_edit_pane_config_form_validate($form, $form_state) {
+  panels_ct_validate_edit_form($form_state['values']['type'], $form['configuration'], $form_state['values']['configuration']);
 }
 
-function panels_edit_pane_config_form_submit($form_id, $form) {
+function panels_edit_pane_config_form_submit($form, $form_state) {
   // save the new configuration.
   $cache = panels_cache_get($form['did']);
 
@@ -860,7 +872,7 @@
   $return->output = theme('panels_pane_collapsible', $block, $cache->display);
 
   panels_set('return', $return);
-  return FALSE;
+  $form_state['redirect'] = FALSE;
 }
 
 /**
@@ -881,7 +893,7 @@
   }
 
   $method = panels_ajax_form('panels_edit_cache_method_form',
-     t('Select cache method'), url($_GET['q'], NULL, NULL, TRUE),
+     t('Select cache method'), url($_GET['q'], array('absolute' => true)),
      $cache->display, $pid);
   return panels_ajax_cache_settings($cache, $pid, $method);
 }
@@ -889,7 +901,7 @@
 /**
  * Choose cache method form
  */
-function panels_edit_cache_method_form($display, $pid) {
+function panels_edit_cache_method_form($form_state, $display, $pid) {
   $conf = $pid ? $display->content[$pid]->cache : $display->cache;
 
   // Set to 0 to ensure we get a selected radio.
@@ -929,8 +941,8 @@
  *
  * All this needs to do is return the method.
  */
-function panels_edit_cache_method_form_submit($form_id, $form_values) {
-  return $form_values['method'];
+function panels_edit_cache_method_form_submit($form, $form_state) {
+  $form_state['redirect'] = $form_state['values']['method'];
 }
 
 /**
@@ -947,7 +959,7 @@
   }
   else {
     $cache->display = panels_ajax_form('panels_edit_cache_settings_form',
-      t('Configure cache settings'), url($_GET['q'], NULL, NULL, TRUE),
+      t('Configure cache settings'), url($_GET['q'], array('absolute' => true)),
       $cache->display, $pid, $method, $function);
   }
 
@@ -973,7 +985,7 @@
 /**
  * Cache settings form
  */
-function panels_edit_cache_settings_form($display, $pid, $method, $settings_function) {
+function panels_edit_cache_settings_form($form_state, $display, $pid, $method, $settings_function) {
   $conf = $pid ? $display->content[$pid]->cache : $display->cache;
   $info = panels_get_cache($method);
 
@@ -1010,27 +1022,24 @@
 /**
  * Validate cache settings.
  */
-function panels_edit_cache_settings_form_validate($form_id, $form_values, $form) {
-  $method = $form_values['method'];
-  if ($function = panels_plugin_get_function('cache', $method, 'settings form validate')) {
-    $function($form, $form_values['settings']);
+function panels_edit_cache_settings_form_validate($form, $form_state) {
+  if ($function = panels_plugin_get_function('cache', $form_state['values']['method'], 'settings form validate')) {
+    $function($form, $form_state['values']['settings']);
   }
 }
 
 /**
  * Allows panel styles to validate their style settings.
  */
-function panels_edit_cache_settings_form_submit($form_id, $form_values) {
-  if ($function = panels_plugin_get_function('cache', $method, 'settings form submit')) {
-    $function($form_values['settings']);
+function panels_edit_cache_settings_form_submit($form, $form_state) {
+  $values = $form_state['values'];
+  if ($function = panels_plugin_get_function('cache', $values['method'], 'settings form submit')) {
+    $function($values['settings']);
   }
 
   // Identify which configuration we're setting
-  $pid = $form_values['pid'];
-  $display = $form_values['display'];
-
-  panels_ajax_set_cache_data($display, $pid, $form_values['method'], $form_values['settings']);
-  return $display;
+  panels_ajax_set_cache_data($values['display'], $values['pid'], $values['method'], $values['settings']);
+  $form_state['redirect'] = $values['display'];
 }
 
 function panels_edit_submit_subform($display) {
@@ -1131,7 +1140,7 @@
   );
 
   // Set up the AJAX settings for the modal.
-  $modals['#panels-style-settings'] = array(url('panels/ajax/panel_settings/' . $display->did . '/default', NULL, NULL, TRUE), '#panel-settings-style');
+  $modals['#panels-style-settings'] = array(url('panels/ajax/panel_settings/' . $display->did . '/default',  array('absolute' => true)), '#panel-settings-style');
 
   $form['panel_settings']['end_box'] = array(
     '#value' => '</div>',
@@ -1173,7 +1182,7 @@
     $checkboxes[] = '#panels-style-settings-' . $id;
 
     // Set up the AJAX settings for the modal.
-    $modals['#panels-style-settings-' . $id ] = array(url('panels/ajax/panel_settings/' . $display->did . '/' . $id, NULL, NULL, TRUE), '#panel-settings-style-' . $id);
+    $modals['#panels-style-settings-' . $id ] = array(url('panels/ajax/panel_settings/' . $display->did . '/' . $id, array('absolute' => true)), '#panel-settings-style-' . $id);
 
     $form['panel_settings']['panel'][$id]['end_box'] = array(
       '#value' => '</div>',
@@ -1208,13 +1217,13 @@
   return $form;
 }
 
-function panels_panel_settings_validate($form_id, $form_values, $form) {
-  $settings = panels_common_cache_get('style_settings', $form_values['panel_settings']['did']);
-  form_set_value($form['panel_settings']['style_settings'], $settings);
+function panels_panel_settings_validate($form, $form_state) {
+  $settings = panels_common_cache_get('style_settings', $form_state['values']['panel_settings']['did']);
+  form_set_value($form['panel_settings']['style_settings'], $settings, $form_state);
 }
 
-function panels_panel_settings_submit($form_id, $form_values) {
-  panels_common_cache_clear('style_settings', $form_values['panel_settings']['did']);
+function panels_panel_settings_submit($form, $form_state) {
+  panels_common_cache_clear('style_settings', $form_state['values']['panel_settings']['did']);
 }
 
 /**
@@ -1235,7 +1244,7 @@
   // submit; otherwise the form is rendered for us and nothing else happens.
   $style_settings[$panel] = panels_ajax_form('panels_common_style_settings_form',
      t('Edit style settings for @style', array('@style' => $style['title'])),
-    url($_GET['q'], NULL, NULL, TRUE),
+    url($_GET['q'],  array('absolute' => true)),
     $did, $style, $style_settings[$panel]);
 
   panels_common_cache_set('style_settings', $did, $style_settings);
@@ -1287,25 +1296,25 @@
 /**
  * Allows panel styles to validate their style settings.
  */
-function panels_common_style_settings_form_validate($form_id, $form_values, $form) {
-  $style = $form_values['style'];
+function panels_common_style_settings_form_validate($form, $form_state) {
+  $style = $form_state['values']['style'];
 
   if (isset($style['settings form validate']) && function_exists($style['settings form validate'])) {
-    $style['settings form validate']($form, $form_values['style_settings']);
+    $style['settings form validate']($form, $form_state['values']['style_settings']);
   }
 }
 
 /**
  * Allows panel styles to validate their style settings.
  */
-function panels_common_style_settings_form_submit($form_id, $form_values) {
-  $style = $form_values['style'];
+function panels_common_style_settings_form_submit($form, $form_state) {
+  $style = $form_state['values']['style'];
 
   if (isset($style['settings form submit']) && function_exists($style['settings form submit'])) {
-    $style['settings form submit']($form_values['style_settings']);
+    $style['settings form submit']($form_state['values']['style_settings']);
   }
 
-  return $form_values['style_settings'];
+  $form_state['redirect'] = $form_state['values']['style_settings'];
 }
 
 /**
@@ -1319,83 +1328,13 @@
   drupal_add_js(panels_get_path('js/lib/dimensions.js'));
   drupal_add_js(panels_get_path('js/lib/mc.js'));
   drupal_add_js(panels_get_path('js/lib/form.js'));
-  drupal_add_js(array('panelsAjaxURL' => url('panels/ajax', NULL, NULL, TRUE)), 'setting');
+
+  // drupal_add_js(array('panelsAjaxURL' => url('panels/ajax', NULL, NULL, TRUE)), 'setting');
   drupal_add_js(panels_get_path('js/display_editor.js'));
   drupal_add_js(panels_get_path('js/checkboxes.js'));
   drupal_add_js(panels_get_path('js/modal_forms.js'));
+
   drupal_add_css(panels_get_path('css/panels_dnd.css'));
   drupal_add_css(panels_get_path('css/panels_admin.css'));
-}
-
-// ---------------------------------------------------------------------------
-// Panels theming functions
-
-// @DND
-function theme_panels_dnd($content) {
-  $output = "<div class=\"panels-dnd\" id=\"panels-dnd-main\">$content</div>";
-  return $output;
-}
-
-// @DND
-function theme_panels_panel_dnd($content, $area, $label, $footer) {
-  return "<div class=\"panels-display\" id=\"panel-pane-$area\">$footer<h2 class=\"label\">$label</h2>$content</div>";
-}
-
-// @DND
-function theme_panels_pane_dnd($block, $id, $label, $left_buttons = NULL, $buttons = NULL) {
-  if (!$block->title) {
-    $block->title = t('No title');
-  }
-  static $count = 0;
-  $output .= "<div class=\"grabber\">";
-  if ($buttons) {
-    $output .= "<span class='buttons'>$buttons</span>";
-  }
-  if ($left_buttons) {
-    $output .= "<span class='left_buttons'>$left_buttons</span>";
-  }
-  $output .= "<span class=\"text\">$label</span></div>";
-  $output .= '<div class="panel-pane-collapsible">';
-  $output .= theme('panels_pane_collapsible', $block);
-  $output .= '</div>';
-  return $output;
-}
 
-// @DND
-function theme_panels_pane_collapsible($block) {
-  $output .= '<h2 class="title">' . $block->title . '</h2>';
-  $output .= '<div class="content">' . filter_xss_admin($block->content) . '</div>';
-  return $output;
-}
-
-/**
- * This is separate because it must be outside the <form> to work, and
- * everything in the form theme is inside the form.
- */
-// @DND
-function theme_panels_hidden() {
-  $close_text = t('Close Window');
-  $close_image = theme('image', panels_get_path('images/icon-delete.png'), t('Close window'), t('Close window'));
-  $throbber_image = theme('image', panels_get_path('images/throbber.gif'), t('Loading...'), t('Loading'));
-  $output = <<<EOF
-<div class="panels-hidden">\n
-  <div id="panels-modal">\n
-    <div class="panels-modal-content">\n
-       <div class="modal-header">\n
-         <a class="close" href="#">$close_text $close_image</a>\n
-         <span class="modal-title">&nbsp;</span>\n
-       </div>\n
-       <div class="modal-content">\n
-       </div>\n
-    </div>\n
-  </div>\n
-  <div id="panels-throbber">\n
-    <div class="panels-throbber-wrapper">
-      $throbber_image\n
-    </div>
-  </div>\n
-</div>\n
-EOF;
-
-  return $output;
 }
Index: panels/includes/plugins.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/includes/Attic/plugins.inc,v
retrieving revision 1.1.2.24
diff -u -r1.1.2.24 plugins.inc
--- panels/includes/plugins.inc	28 Mar 2008 08:02:14 -0000	1.1.2.24
+++ panels/includes/plugins.inc	30 Apr 2008 10:19:20 -0000
@@ -166,7 +166,7 @@
  *   The arguments to the content type.
  * @param $context
  *   The panels_context object.
- * @Param $incoming_content
+ * @param $incoming_content
  *   Any incoming content, if this display is a wrapper.
  */
 function panels_ct_get_content($type, $conf, $args, $context, $incoming_content) {
@@ -1267,7 +1267,8 @@
  *
  * @param $plugintype
  *   The plugin type, as well as the panels directory where the plugin is kept.
- *   A list of additional directories to search for relevant plugins is generated by invoking hook_panels_include_directory();
+ *   A list of additional directories to search for relevant plugins is
+ *   generated by invoking hook_panels_include_directory();
  * @param $hook
  *   The name of the hook to be invoked.
  * @param $file
@@ -1329,7 +1330,7 @@
 
 /**
  * Load plugin info for all hooks; this is handled separately from plugins
- * from files. This is cached so we don't find ourselves building htis
+ * from files. This is cached so we don't find ourselves building this
  * repeatedly.
  *
  * @param $hook
@@ -1365,7 +1366,7 @@
     return NULL;
   }
   $result = $function();
-  if (!isset($result) ||  !is_array($result)) {
+  if (!isset($result) || !is_array($result)) {
     return NULL;
   }
 
@@ -1435,47 +1436,25 @@
 }
 
 /**
- * Fetch a layout plugin
- *
- * @param $layout
- *   Name of a panel layout.
- * @return
- *   An array with information about the requested panel layout.
- */
-function panels_get_layout($layout) {
-  return panels_get_plugins('layouts', 'panels_layouts', $layout);
-}
-
-/**
- * Fetch all layout plugins
- *
- * @return
- *   An array of arrays with information about all available panel layouts.
- */
-function panels_get_layouts() {
-  return panels_get_plugins('layouts', 'panels_layouts');
-}
-
-/**
- * Collate information about a specific panel style.
+ * Fetch a content_type plugin
  *
- * @param $style
- *   Name of a panel style.
+ * @param $content type
+ *   Name of a panel content type.
  * @return
- *   An array with information about the requested panel style.
+ *   An array with information about the requested panel content type.
  */
-function panels_get_style($style) {
-  return panels_get_plugins('styles', 'panels_styles', $style);
+function panels_get_content_type($content_type) {
+  return panels_get_plugins('content_types', 'panels_content_types', $content_type);
 }
 
 /**
- * Collate information about all available panel styles.
+ * Fetch all content type plugins
  *
  * @return
- *   An array of arrays with information about all available panel styles.
+ *   An array of arrays with information about all available panel content types.
  */
-function panels_get_styles() {
-  return panels_get_plugins('styles', 'panels_styles');
+function panels_get_content_types() {
+  return panels_get_plugins('content_types', 'panels_content_types');
 }
 
 /**
@@ -1501,28 +1480,6 @@
 }
 
 /**
- * Fetch a content_type plugin
- *
- * @param $content type
- *   Name of a panel content type.
- * @return
- *   An array with information about the requested panel content type.
- */
-function panels_get_content_type($content_type) {
-  return panels_get_plugins('content_types', 'panels_content_types', $content_type);
-}
-
-/**
- * Fetch all content type plugins
- *
- * @return
- *   An array of arrays with information about all available panel content types.
- */
-function panels_get_content_types() {
-  return panels_get_plugins('content_types', 'panels_content_types');
-}
-
-/**
  * Fetch a relationship plugin
  *
  * @param $content type
@@ -1587,3 +1544,47 @@
 function panels_get_caches() {
   return panels_get_plugins('cache', 'panels_cache');
 }
+
+/**
+ * Fetch a layout plugin
+ *
+ * @param $layout
+ *   Name of a panel layout.
+ * @return
+ *   An array with information about the requested panel layout.
+ */
+function panels_get_layout($layout) {
+  return panels_get_plugins('layouts', 'panels_layouts', $layout);
+}
+
+/**
+ * Fetch all layout plugins
+ *
+ * @return
+ *   An array of arrays with information about all available panel layouts.
+ */
+function panels_get_layouts() {
+  return panels_get_plugins('layouts', 'panels_layouts');
+}
+
+/**
+ * Collate information about a specific panel style.
+ *
+ * @param $style
+ *   Name of a panel style.
+ * @return
+ *   An array with information about the requested panel style.
+ */
+function panels_get_style($style) {
+  return panels_get_plugins('styles', 'panels_styles', $style);
+}
+
+/**
+ * Collate information about all available panel styles.
+ *
+ * @return
+ *   An array of arrays with information about all available panel styles.
+ */
+function panels_get_styles() {
+  return panels_get_plugins('styles', 'panels_styles');
+}
Index: panels/includes/common.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/includes/Attic/common.inc,v
retrieving revision 1.1.2.21
diff -u -r1.1.2.21 common.inc
--- panels/includes/common.inc	31 Dec 2007 06:30:16 -0000	1.1.2.21
+++ panels/includes/common.inc	30 Apr 2008 10:19:20 -0000
@@ -7,11 +7,17 @@
 */
 
 /**
- * A common settings page for Panels modules, because this code is relevant to
- * any modules that don't already ahve special requirements.
+ * A common settings form for Panels modules.
+ *
+ * Displayed at admin/panels/%module%/settings.
+ * This code is relevant to any modules that don't already have
+ * special requirements.
  */
-function panels_common_settings($module_name = 'panels_common') {
+function panels_common_settings_form($form_state, $module_name = 'panels_common') {
   panels_load_include('plugins');
+  drupal_add_css(panels_get_path('css/panels_page.css'));
+
+  // 'New content behavior' section:
   $content_types = panels_get_content_types();
   $default_types = variable_get($module_name . '_default', NULL);
   if (!isset($default_types)) {
@@ -21,11 +27,11 @@
 
   foreach ($content_types as $id => $info) {
     if (empty($info['single'])) {
-      $default_options[$id] = t('New @s', array('@s' => $info['title']));
+      $default_options[$id] = t('New @content_type', array('@content_type' => $info['title']));
     }
   }
-
   $default_options['other'] = t('New content of other types');
+
   $form['panels_common_default'] = array(
     '#type' => 'checkboxes',
     '#title' => t('New content behavior'),
@@ -34,9 +40,10 @@
     '#default_value' => array_keys(array_filter($default_types)),
   );
 
+  // 'Allowed * content' section: Show only if not skipped.
   if ($skip) {
     $form['markup'] = array('#value' => t('<p>Click Submit to be presented with a complete list of available content types set to the defaults you selected.</p>'));
-    $form['skip'] = array('#type' => 'value', '#value' => TRUE);
+    $form_state['skip'] = TRUE;
   }
   else {
     // Rebuild the entire list, setting appropriately from defaults. Give
@@ -59,16 +66,17 @@
       }
     }
 
-    $form['content_types'] = array('#tree' => TRUE);
     // cheat a bit
     $content_types['other'] = array('title' => t('Other'), 'weight' => 10);
+
+    $form['content_types'] = array('#tree' => TRUE);
     foreach ($content_types as $id => $info) {
       if (isset($allowed[$id])) {
         $form['content_types'][$id] = array(
           '#prefix' => '<div class="panels-page-type-container">',
           '#suffix' => '</div>',
           '#type' => 'checkboxes',
-          '#title' => t('Allowed @s content', array('@s' => $info['title'])),
+          '#title' => t('Allowed @content_type content', array('@content_type' => $info['title'])),
           '#options' => $options[$id],
           '#default_value' => array_keys(array_filter($allowed[$id])),
         );
@@ -76,29 +84,21 @@
     }
   }
 
-  $form['module_name'] = array(
-    '#type' => 'value',
-    '#value' => $module_name,
-  );
-
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit'),
   );
 
-  drupal_add_css(panels_get_path('css/panels_page.css'));
+  $form_state['module_name'] = $module_name;
+
   return $form;
 }
 
-/**
- * Submit hook for panels_common_settings
- */
-function panels_common_settings_submit($form_id, $form_values) {
-  $module_name = $form_values['module_name'];
-  variable_set($module_name . '_default', $form_values['panels_common_default']);
-  if (!$form_values['skip']) {
+function panels_common_settings_form_submit($form, &$form_state) {
+  variable_set($form_state['module_name'] . '_default', $form_state['values']['panels_common_default']);
+  if (!$form_state['skip']) {
     // merge the broken apart array neatly back together
-    variable_set($module_name . '_allowed_types', call_user_func_array('array_merge', $form_values['content_types']));
+    variable_set($form_state['module_name'] . '_allowed_types', call_user_func_array('array_merge', $form_state['values']['content_types']));
   }
   drupal_set_message(t('Your changes have been saved.'));
 }
@@ -234,44 +234,42 @@
 /**
  * Add the argument table plus gadget plus javascript to the form.
  */
-function panels_common_add_argument_form($module, &$form, &$form_location, $object) {
+function panels_common_add_argument_form($module, &$form, &$form_location, $panel_page) {
+  $form['arguments'] = array(
+    '#type' => 'value',
+    '#value' => $panel_page->arguments,
+  );
+
   $form_location = array(
+    '#prefix' => '<div id="panels-arguments-table">',
+    '#suffix' => '</div>',
     '#theme' => 'panels_common_context_item_form',
-    '#panel_name' => $object->name,
+    '#panel_name' => $panel_page->name,
     '#panels_context_type' => 'argument',
     '#panels_context_module' => $module,
   );
 
-  $form['arguments'] = array(
-    '#type' => 'value',
-    '#value' => $object->arguments,
-  );
-
   // Store the order the choices are in so javascript can manipulate it.
   $form['argument_order'] = array(
     '#type' => 'hidden',
     '#id' => 'argument-order',
-    '#default_value' => $object->arguments ? implode(',', array_keys($object->arguments)) : '',
+    '#default_value' => $panel_page->arguments ? implode(',', array_keys($panel_page->arguments)) : '',
   );
 
-  $args = panels_get_arguments();
   $choices = array();
-  foreach ($args as $name => $arg) {
+  foreach (panels_get_arguments() as $name => $arg) {
     $choices[$name] = $arg['title'];
   }
-
   asort($choices);
 
-  if (!empty($choices) || !empty($object->arguments)) {
-    panels_common_add_item_table('argument', $form_location, $choices, $object->arguments);
-  }
-  return _panels_common_context_js($object->name, $module, 'argument');
+  panels_common_add_item_table('argument', $form_location, $choices, $panel_page->arguments);
+  return _panels_common_context_js($panel_page->name, $module, 'argument');
 }
 
-function panels_common_add_context_form($module, &$form, &$form_location, $object) {
+function panels_common_add_context_form($module, &$form, &$form_location, $panel_page) {
   $form['contexts'] = array(
     '#type' => 'value',
-    '#value' => $object->contexts,
+    '#value' => $panel_page->contexts,
   );
 
   $form_location = array(
@@ -290,7 +288,7 @@
   $form['context_order'] = array(
     '#type' => 'hidden',
     '#id' => 'context-order',
-    '#default_value' => $object->contexts ? implode(',', array_keys($object->contexts)) : '',
+    '#default_value' => $panel_page->contexts ? implode(',', array_keys($panel_page->contexts)) : '',
   );
 
   $choices = array();
@@ -299,16 +297,13 @@
       $choices[$name] = $arg['title'];
     }
   }
-
   asort($choices);
 
-  if (!empty($choices) || !empty($object->contexts)) {
-    panels_common_add_item_table('context', $form_location, $choices, $object->contexts);
-  }
-  return _panels_common_context_js($object->name, $module, 'context');
+  panels_common_add_item_table('context', $form_location, $choices, $panel_page->contexts);
+  return _panels_common_context_js($panel_page->name, $module, 'context');
 }
 
-function panels_common_add_required_context_form($module, &$form, &$form_location, $object) {
+function panels_common_add_required_context_form($module, &$form, &$form_location, $panel_page) {
   $form['requiredcontexts'] = array(
     '#type' => 'value',
     '#value' => $object->requiredcontexts,
@@ -337,26 +332,23 @@
   foreach (panels_get_contexts() as $name => $arg) {
     $choices[$name] = $arg['title'];
   }
-
   asort($choices);
 
-  if (!empty($choices) || !empty($object->contexts)) {
-    panels_common_add_item_table('requiredcontext', $form_location, $choices, $object->requiredcontexts);
-  }
+  panels_common_add_item_table('requiredcontext', $form_location, $choices, $object->requiredcontexts);
   return _panels_common_context_js($object->name, $module, 'requiredcontext');
 }
 
-function panels_common_add_relationship_form($module, &$form, &$form_location, $object) {
+function panels_common_add_relationship_form($module, &$form, &$form_location, $panel_page) {
   $form['relationships'] = array(
     '#type' => 'value',
-    '#value' => $object->relationships,
+    '#value' => $panel_page->relationships,
   );
 
   $form_location = array(
     '#prefix' => '<div id="panels-relationships-table">',
     '#suffix' => '</div>',
     '#theme' => 'panels_common_context_item_form',
-    '#panel_name' => $object->name,
+    '#panel_name' => $panel_page->name,
     '#panels_context_type' => 'relationship',
     '#panels_context_module' => $module,
   );
@@ -368,16 +360,13 @@
   $form['relationship_order'] = array(
     '#type' => 'hidden',
     '#id' => 'relationship-order',
-    '#default_value' => $object->relationships ? implode(',', array_keys($object->relationships)) : '',
+    '#default_value' => $panel_page->relationships ? implode(',', array_keys($panel_page->relationships)) : '',
   );
 
-  $available_relationships = panels_get_relevant_relationships(panels_context_load_contexts($object));
-
-//  if (!empty($available_relationships) || !empty($object->relationships)) {
-    panels_common_add_item_table('relationship', $form_location, $available_relationships, $object->relationships);
-//  }
+  $choices = panels_get_relevant_relationships(panels_context_load_contexts($panel_page));
 
-  return _panels_common_context_js($object->name, $module, 'relationship');
+  panels_common_add_item_table('relationship', $form_location, $choices, $panel_page->relationships);
+  return _panels_common_context_js($panel_page->name, $module, 'relationship');
 }
 
 function _panels_common_context_js($name, $module, $type) {
@@ -391,12 +380,12 @@
     'top' => "input.$type-top",
     'bottom' => "input.$type-bottom",
     'configure' => "input.$type-settings",
-    'configure_path' => url("panels/common/ajax/edit/$module/$type/$name", NULL, NULL, TRUE),
+    'configure_path' => url("panels/common/ajax/edit/$module/$type/$name", array('absolute' => true)),
 
     // The button that adds an item
     'add' => "input#edit-buttons-$type-add",
     // Path for ajax on adding an item
-    'path' => url("panels/common/ajax/add/$module/$type/$name", NULL, NULL, TRUE),
+    'path' => url("panels/common/ajax/add/$module/$type/$name", array('absolute' => true)),
     // Which items to post when adding
     'post' => array("#edit-buttons-$type-item", "input#edit-buttons-$type-add"),
     // Where to get the id of an item
@@ -432,36 +421,38 @@
 /**
  * Add the context table to the page.
  */
-function panels_common_add_item_table($type, &$form, $available_contexts, $items) {
-  $form[$type] = array(
-    '#tree' => TRUE,
-  );
-
-  if (isset($items) && is_array($items)) {
-    foreach ($items as $position => $context) {
-      panels_common_add_item_to_form($type, $form[$type][$position], $position, $context);
+function panels_common_add_item_table($type, &$form, $choices, $items) {
+  if (!empty($choices) || !empty($items)) {
+    $form[$type] = array(
+      '#tree' => TRUE,
+    );
+  
+    if (isset($items) && is_array($items)) {
+      foreach ($items as $position => $context) {
+        panels_common_add_item_to_form($type, $form[$type][$position], $position, $context);
+      }
     }
+  
+    $type_info = panels_common_context_info($type);
+    $form['description'] = array(
+      '#prefix' => '<div class="description">',
+      '#suffix' => '</div>',
+      '#value' => $type_info['description'],
+    );
+  
+    panels_common_add_item_table_buttons($type, $form, $choices);
   }
-
-  $type_info = panels_common_context_info($type);
-  $form['description'] = array(
-    '#prefix' => '<div class="description">',
-    '#suffix' => '</div>',
-    '#value' => $type_info['description'],
-  );
-
-  panels_common_add_item_table_buttons($type, $form, $available_contexts);
 }
 
-function panels_common_add_item_table_buttons($type, &$form, $available_contexts) {
+function panels_common_add_item_table_buttons($type, &$form, $choices) {
   $form['buttons'] = array(
     '#tree' => TRUE,
   );
 
-  if (!empty($available_contexts)) {
+  if (!empty($choices)) {
     $form['buttons'][$type]['item'] = array(
       '#type' => 'select',
-      '#options' => $available_contexts,
+      '#options' => $choices,
     );
 
     $type_info = panels_common_context_info($type);
@@ -527,78 +518,6 @@
 }
 
 /**
- * Theme the form item for the context entry.
- */
-function theme_panels_common_context_item_row($type, $form, $position, $count, $with_tr = TRUE) {
-  $output = '<td class="title">&nbsp;' . drupal_render($form['title']) . '</td>';
-
-  $arrows = '';
-  $type_info = panels_common_context_info($type);
-  if (!empty($type_info['sortable'])) {
-    $arrows = drupal_render($form['up']) .
-              drupal_render($form['down']) .
-              drupal_render($form['top']) .
-              drupal_render($form['bottom']);
-  }
-
-  $output .= '<td class="operation">' . drupal_render($form['settings']) .
-    $arrows . drupal_render($form['remove']) .
-  '</td>';
-  if ($with_tr) {
-    $output = '<tr id="' . $type . '-row-' . $position . '" class="' . $type . '-row ' . ($count % 2 ? 'even' : 'odd') . '">' . $output . '</tr>';
-  }
-  return $output;
-}
-
-/**
- * Add the contexts form to panel page settings
- */
-function theme_panels_common_context_item_form($form) {
-  $output = '';
-  $type = $form['#panels_context_type'];
-  $module = $form['#panels_context_module'];
-  $name = $form['#panel_name'];
-
-  $type_info = panels_common_context_info($type);
-
-  if (!empty($form[$type]) && empty($form['#only_buttons'])) {
-    $output .= '<table id="' . $type . '-table">';
-    $output .= '<thead>';
-    $output .= '<tr>';
-    $output .= '<th class="title">' . $type_info['title'] . '</th>';
-    $output .= '<th class="operation operation">' . t('Operation') . '</th>';
-    $output .= '</thead>';
-    $output .= '<tbody>';
-
-    $count = 0;
-    foreach (array_keys($form[$type]) as $id) {
-      if (!is_numeric($id)) {
-        continue;
-      }
-      $output .= theme('panels_common_context_item_row', $type, $form[$type][$id], $id, $count++);
-    }
-
-    $output .= '</tbody>';
-    $output .= '</table>';
-  }
-
-  if (!empty($form['buttons'])) {
-    // Display the add context item.
-    $row = array();
-    $row[] = array('data' => drupal_render($form['buttons'][$type]['item']), 'class' => 'title');
-    $row[] = array('data' => drupal_render($form['buttons'][$type]['add']), 'class' => 'add', 'width' => "60%");
-    $output .= '<div class="buttons">';
-    $output .= theme('table', array(), array($row), array('id' => $type . '-add-table'));
-    $output .= '</div>';
-  }
-  if (!empty($form['description'])) {
-    $output .= drupal_render($form['description']);
-  }
-
-  return $output;
-}
-
-/**
  * Ajax entry point to add an context
  */
 function panels_common_ajax_context_item_add($module, $type, $panel_name) {
@@ -653,7 +572,7 @@
     $form['#redirect'] = FALSE;
   }
 
-  $retval = drupal_process_form($form_id, $form);
+  $retval = drupal_process_form($form_id, $form, $form_state);
   if ($retval) {
     // successful submit
 
@@ -702,7 +621,7 @@
     $title = t('Add @type "@context"', array('@type' => $type_info['singular title'], '@context' => $info['title']));
     $output = theme('status_messages');
     $output .= drupal_render_form($form_id, $form);
-    panels_ajax_render($output, $title, url($_GET['q'], NULL, NULL, TRUE));
+    panels_ajax_render($output, $title, url($_GET['q'], array('absolute' => true)));
   }
 }
 
@@ -784,7 +703,7 @@
   else {
     $output = theme('status_messages');
     $output .= drupal_render_form($form_id, $form);
-    panels_ajax_render($output, $title, url($_GET['q'], NULL, NULL, TRUE));
+    panels_ajax_render($output, $title, url($_GET['q'], array('absolute' => true)));
   }
 }
 
@@ -798,7 +717,10 @@
     '#value' => $position,
   );
 
-  $form['start_form'] = array('#value' => '<div class="modal-form clear-block">');
+  $form['start_form'] = array(
+    '#type' => 'value',
+    '#value' => '<div class="modal-form clear-block">'
+  );
 
   $form['description'] = array(
     '#prefix' => '<div class="description">',
@@ -844,47 +766,42 @@
     $form['context']['context_settings']['#tree'] = TRUE;
   }
 
-  $form['context_info'] = array(
+  $form['end_form'] = array(
     '#type' => 'value',
-    '#value' => $context,
+    '#value' => '</div>'
   );
 
-  $form['end_form'] = array('#value' => '</div>');
-
   $form['next'] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
   );
+
+  $form_state['context_info'] = $context;
+
   return $form;
 }
 
-/**
- * validate a  context edited/added via ajax
- */
-function panels_common_edit_context_form_validate($form_id, $form_values, $form) {
-  $context = $form_values['context_info'];
+function panels_common_edit_context_form_validate($form, &$form_state) {
+  $context = $form_state['context_info'];
 
   if (isset($context['settings form validate']) && function_exists($context['settings form validate'])) {
-    $context['settings form validate']($form['context']['context_settings'], $form_values['context']['context_settings']);
+    $context['settings form validate']($form['context']['context_settings'], $form_state['values']['context']['context_settings']);
   }
 }
 
-/**
- * Updates an context edited/added via ajax
- */
-function panels_common_edit_context_form_submit($form_id, $form_values) {
-  $context = $form_values['context'];
-  $info = $form_values['context_info'];
+function panels_common_edit_context_form_submit($form, &$form_state) {
+  $context = $form_state['values']['context'];
+  $info = $form_state['context_info'];
 
   if (isset($info['settings form submit']) && function_exists($info['settings form submit'])) {
-    $info['settings form submit']($form_values['context_settings']);
+    $info['settings form submit']($form_state['values']['context_settings']);
   }
 
   return $context;
 }
 
 /**
- * Form (for ajax use) to add a context
+ * Form (for ajax use) to add a required context
  */
 function panels_common_edit_requiredcontext_form($object, $context, $position, $contexts) {
   $ctext = $object->requiredcontexts[$position];
@@ -893,7 +810,10 @@
     '#value' => $position,
   );
 
-  $form['start_form'] = array('#value' => '<div class="modal-form clear-block">');
+  $form['start_form'] = array(
+    '#type' => 'value',
+    '#value' => '<div class="modal-form clear-block">'
+  );
 
   $form['description'] = array(
     '#prefix' => '<div class="description">',
@@ -928,24 +848,22 @@
     '#default_value' => $ctext['keyword'],
   );
 
-  $form['context_info'] = array(
+  $form['end_form'] = array(
     '#type' => 'value',
-    '#value' => $context,
+    '#value' => '</div>'
   );
 
-  $form['end_form'] = array('#value' => '</div>');
-
   $form['next'] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
   );
+  
+  $form_state['context_info'] = $context;
+
   return $form;
 }
 
-/**
- * Updates a required context edited/added via ajax
- */
-function panels_common_edit_requiredcontext_form_submit($form_id, $form_values) {
+function panels_common_edit_requiredcontext_form_submit($form, &$form_state) {
   $context = $form_values['requiredcontext'];
   return $context;
 }
@@ -960,7 +878,10 @@
     '#value' => $position,
   );
 
-  $form['start_form'] = array('#value' => '<div class="modal-form clear-block">');
+  $form['start_form'] = array(
+    '#type' => 'value',
+    '#value' => '<div class="modal-form clear-block">'
+  );
 
   $form['description'] = array(
     '#prefix' => '<div class="description">',
@@ -1008,39 +929,34 @@
     $form['relationship']['relationship_settings']['#tree'] = TRUE;
   }
 
-  $form['relationship_info'] = array(
+  $form['end_form'] = array(
     '#type' => 'value',
-    '#value' => $relationship,
+    '#value' => '</div>'
   );
 
-  $form['end_form'] = array('#value' => '</div>');
-
   $form['next'] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
   );
+
+  $form_state['relationship_info'] = $relationship;
+
   return $form;
 }
 
-/**
- * validate an relationship edited/added via ajax
- */
-function panels_common_edit_relationship_form_validate($form_id, $form_values, $form) {
-  $relationship = $form_values['relationship_info'];
+function panels_common_edit_relationship_form_validate($form, &$form_state) {
+  $relationship = $form_state['relationship_info'];
 
   if (isset($relationship['settings form validate']) && function_exists($relationship['settings form validate'])) {
-    $relationship['settings form validate']($form['relationship']['relationship_settings'], $form_values['relationship']['relationship_settings']);
+    $relationship['settings form validate']($form['relationship']['relationship_settings'], $form_state['values']['relationship']['relationship_settings']);
   }
 }
 
-/**
- * Updates an relationship edited/added via ajax
- */
-function panels_common_edit_relationship_form_submit($form_id, $form_values) {
-  $relationship = $form_values['relationship'];
+function panels_common_edit_relationship_form_submit($form, &$form_state) {
+  $relationship = $form_state['values']['relationship'];
 
   if (isset($relationship['settings form submit']) && function_exists($relationship['settings form submit'])) {
-    $relationship['settings form submit']($form_values['relationship_settings']);
+    $relationship['settings form submit']($form_state['values']['relationship_settings']);
   }
 
   return $relationship;
@@ -1058,7 +974,9 @@
     '#value' => $position,
   );
 
-  $form['start_form'] = array('#value' => '<div class="modal-form">');
+  $form['start_form'] = array(
+    '#value' => '<div class="modal-form">'
+  );
 
   $form['description'] = array(
     '#prefix' => '<div class="description">',
@@ -1116,11 +1034,6 @@
     $argument_settings = $arg['argument_settings'];
   }
 
-  $form['arg'] = array(
-    '#type' => 'value',
-    '#value' => $argument,
-  );
-
   if (isset($argument['settings form']) && function_exists($argument['settings form'])) {
     $form['argument']['argument_settings'] = $argument['settings form']($argument_settings);
     $form['argument']['argument_settings']['#tree'] = TRUE;
@@ -1133,33 +1046,29 @@
     '#value' => t('Save'),
   );
 
+  $form_state['arg'] = $argument;
+
   return $form;
 }
 
-/**
- * validate an argument edited/added via ajax
- */
-function panels_common_edit_argument_form_validate($form_id, $form_values, $form) {
-  $argument = $form_values['arg'];
+function panels_common_edit_argument_form_validate($form, &$form_state) {
+  $argument = $form_state['arg'];
 
   if (isset($argument['settings form validate']) && function_exists($argument['settings form validate'])) {
     $argument['settings form validate']($form['argument']['argument_settings'], $form_values['argument']['argument_settings']);
   }
 }
 
-/**
- * Updates an argument edited/added via ajax
- */
-function panels_common_edit_argument_form_submit($form_id, $form_values) {
-  $argument = $form_values['arg'];
-  $position = $form_values['position'];
+function panels_common_edit_argument_form_submit($form, &$form_state) {
+  $argument = $form_state['arg'];
+  $position = $form_state['values']['position'];
 
   if (isset($argument['settings form submit']) && function_exists($argument['settings form submit'])) {
-    $argument['settings form submit']($form_values['argument']['argument_settings']);
+    $argument['settings form submit']($form_state['values']['argument']['argument_settings']);
   }
 
   // Because we're being all ajaxy, our caller will save this for us.
-  return $form_values['argument'];
+  return $form_state['values']['argument'];
 }
 
 // --- End of contexts
@@ -1229,76 +1138,3 @@
   return $keyword;
 }
 
-/**
- * Create a visible list of content in a display.
- * Note that the contexts must be pre-loaded.
- */
-function theme_panels_common_content_list($display) {
-  $layout = panels_get_layout($display->layout);
-  $content = '<dl class="content-list">';
-  foreach (panels_get_panels($layout, $display) as $panel_id => $title) {
-    $content .= "<dt>$title</dt><dd>";
-    if ($display->panels[$panel_id]) {
-      $content .= '<ol>';
-      foreach ($display->panels[$panel_id] as $pid) {
-        $content .= '<li>' . panels_get_pane_title($display->content[$pid], $display->context) . '</li>';
-      }
-      $content .= '</ol>';
-    }
-    else {
-      $content .= t('Empty');
-    }
-    $content .= '</dd>';
-  }
-  $content .= '</dl>';
-  return $content;
-}
-
-/**
- * Create a visible list of all the contexts available on an object.
- * Assumes arguments, relationships and context objects.
- *
- * Contexts must be preloaded.
- */
-function theme_panels_common_context_list($object) {
-  $titles = array();
-  $output = '';
-  $count = 1;
-  // First, make a list of arguments. Arguments are pretty simple.
-  if (!empty($object->arguments)) {
-    foreach ($object->arguments as $argument) {
-      $output .= '<tr>';
-      $output .= '<td><em>' . t('Argument @count', array('@count' => $count)) . '</em></td>';
-      $output .= '<td>' . check_plain($argument['identifier']) . '</td>';
-      $output .= '</tr>';
-      $titles[panels_argument_context_id($argument)] = $argument['identifier'];
-      $count++;
-    }
-  }
-  $count = 1;
-  // Then, make a nice list of contexts.
-  if (!empty($object->contexts)) {
-    foreach ($object->contexts as $context) {
-      $output .= '<tr>';
-      $output .= '<td><em>' . t('Context @count', array('@count' => $count)) . '</em></td>';
-      $output .= '<td>' . check_plain($context['identifier']) . '</td>';
-      $output .= '</tr>';
-      $titles[panels_context_context_id($context)] = $context['identifier'];
-      $count++;
-    }
-  }
-  // And relationships
-  if (!empty($object->relationships)) {
-    foreach ($object->relationships as $relationship) {
-      $output .= '<tr>';
-      $output .= '<td><em>' . t('From @title', array('@title' => $titles[$relationship['context']])) . '</em></td>';
-      $output .= '<td>' . check_plain($relationship['identifier']) . '</td>';
-      $output .= '</tr>';
-      $titles[panels_relationship_context_id($relationship)] = $relationship['identifier'];
-      $count++;
-    }
-  }
-  if ($output) {
-    return "<table><tbody>$output</tbody></table>\n";
-  }
-}
Index: panels/css/panels_admin.css
===================================================================
RCS file: /cvs/drupal/contributions/modules/panels/css/Attic/panels_admin.css,v
retrieving revision 1.1.2.18
diff -u -r1.1.2.18 panels_admin.css
--- panels/css/panels_admin.css	31 Dec 2007 00:35:05 -0000	1.1.2.18
+++ panels/css/panels_admin.css	30 Apr 2008 10:19:19 -0000
@@ -63,29 +63,29 @@
 }
 
 /* styles for the choose layout page */
-#panels-choose-layout .form-radios .form-item {
+#panels-edit-layout-form .form-radios .form-item {
   float: left;
   margin-right: .5em;
   width: 90px;
 }
 
-#panels-choose-layout .form-radios .form-item .layout-icon {
+#panels-edit-layout-form .form-radios .form-item .layout-icon {
   float: none;
   height: 15em;
   width: 90px;
 }
 
-#panels-choose-layout .form-radios .form-item .option {
+#panels-edit-layout-form .form-radios .form-item .option {
   width: 50px;
   display: block;
   text-align: center; 
 }
 
-#panels-choose-layout .form-submit {
+#panels-edit-layout-form .form-submit {
   clear: left;
 }
 
-#panels-choose-layout .panels-layout-list label {
+#panels-edit-layout-form .panels-layout-list label {
   width: 300px;
   float: left;
   clear: left;
Index: panels/panels.callbacks.inc
===================================================================
RCS file: panels/panels.callbacks.inc
diff -N panels/panels.callbacks.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ panels/panels.callbacks.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,60 @@
+<?php
+// $Id: panels.module,v 1.10.4.82 2008/02/10 07:48:19 merlinofchaos Exp $
+/**
+ * @file panels.callbacks.inc
+ * Core menu callbacks for Panels.
+ */
+
+
+
+/**
+ * Helper function for autocompletion of node titles.
+ * This is mostly stolen from clipper.
+ */
+function panels_node_autocomplete($string) {
+  // TODO: Compare this to the nodequeue version, see which is better.
+  // TODO: The nodequeue version is totally better. Steal it.
+  if ($string != '') { // if there are node_types passed, we'll use those in a MySQL IN query.
+    $preg_matches = array();
+    $match = preg_match('/\[nid: (\d+)\]/', $string, $preg_matches);
+    if (!$match) {
+      $match = preg_match('/^nid: (\d+)/', $string, $preg_matches);
+    }
+    if ($match) {
+      $arg = $preg_matches[1];
+      $where = "n.nid = %d";
+    }
+    else {
+      $arg = $string;
+      $where = "LOWER(title) LIKE LOWER('%%%s%%')";
+    }
+    $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, u.name FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE $where"), $arg, 0, 10);
+
+    $matches = array();
+    while ($node = db_fetch_object($result)) {
+      $name = empty($node->name) ? variable_get('anonymous', t('Anonymous')) : check_plain($node->name);
+      $matches[$node->title . " [nid: $node->nid]"] = '<span class="autocomplete_title">'. check_plain($node->title) .'</span> <span class="autocomplete_user">('. t('by @user', array('@user' => $name)) .')</span>';
+    }
+    drupal_set_header('Content-Type: text/javascript; charset=utf-8');
+    print drupal_to_js($matches);
+  }
+}
+
+
+
+/**
+ * Helper function for our AJAX stuff to call through to the right location
+ */
+function panels_ajax_passthru() {
+  $args = func_get_args();
+  $callback = array_shift($args);
+
+  panels_load_include('plugins');
+  if (arg(1) == 'common') {
+    panels_load_include('common');
+  }
+  else {
+    panels_load_include('display_edit');
+  }
+  return call_user_func_array($callback, $args);
+}
Index: panels/includes/theme.inc
===================================================================
RCS file: panels/includes/theme.inc
diff -N panels/includes/theme.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ panels/includes/theme.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,285 @@
+<?php
+// $Id: panels.module,v 1.10.4.82 2008/02/10 07:48:19 merlinofchaos Exp $
+/**
+ * @file panels.theme.inc
+ * Core theme functions for Panels.
+ */
+
+/**
+ * Render a panel pane like a block.
+ *
+ * A panel pane can have the following fields:
+ *
+ * $pane->type -- the content type inside this pane
+ * $pane->subtype -- The subtype, if applicable. If a view it will be the
+ *   view name; if a node it will be the nid, etc.
+ * $content->title -- The title of the content
+ * $content->content -- The actual content
+ * $content->links -- Any links associated with the content
+ * $content->more -- An optional 'more' link (destination only)
+ * $content->admin_links -- Administrative links associated with the content
+ * $content->feeds -- Any feed icons or associated with the content
+ * $content->subject -- A legacy setting for block compatibility
+ * $content->module -- A legacy setting for block compatibility
+ * $content->delta -- A legacy setting for block compatibility
+ */
+function theme_panels_pane($content, $pane, $display) {
+  if (!empty($content->content)) {
+    $idstr = $classstr = '';
+    if (!empty($content->css_id)) {
+      $idstr = ' id="' . $content->css_id . '"';
+    }
+    if (!empty($content->css_class)) {
+      $classstr = ' ' . $content->css_class;
+    }
+
+    $output = "<div class=\"panel-pane$classstr\"$idstr>\n";
+    if (user_access('view pane admin links') && !empty($content->admin_links)) {
+      $output .= "<div class=\"admin-links panel-hide\">" . theme('links', $content->admin_links) . "</div>\n";
+    }
+    if (!empty($content->title)) {
+      $output .= "<h2 class=\"title\">$content->title</h2>\n";
+    }
+
+    if (!empty($content->feeds)) {
+      $output .= "<div class=\"feed\">" . implode(' ', $content->feeds) . "</div>\n";
+    }
+
+    $output .= "<div class=\"content\">$content->content</div>\n";
+
+    if (!empty($content->links)) {
+      $output .= "<div class=\"links\">" . theme('links', $content->links) . "</div>\n";
+    }
+
+
+    if (!empty($content->more)) {
+      if (empty($content->more['title'])) {
+        $content->more['title'] = t('more');
+      }
+      $output .= "<div class=\"more-link\">" . l($content->more['title'], $content->more['href']) . "</div>\n";
+    }
+
+    $output .= "</div>\n";
+    return $output;
+  }
+}
+
+/**
+ * Create a visible list of content in a display.
+ * Note that the contexts must be pre-loaded.
+ */
+function theme_panels_common_content_list($display) {
+  $layout = panels_get_layout($display->layout);
+  $content = '<dl class="content-list">';
+  foreach (panels_get_panels($layout, $display) as $panel_id => $title) {
+    $content .= "<dt>$title</dt><dd>";
+    if ($display->panels[$panel_id]) {
+      $content .= '<ol>';
+      foreach ($display->panels[$panel_id] as $pid) {
+        $content .= '<li>' . panels_get_pane_title($display->content[$pid], $display->context) . '</li>';
+      }
+      $content .= '</ol>';
+    }
+    else {
+      $content .= t('Empty');
+    }
+    $content .= '</dd>';
+  }
+  $content .= '</dl>';
+  return $content;
+}
+
+/**
+ * Create a visible list of all the contexts available on an object.
+ * Assumes arguments, relationships and context objects.
+ *
+ * Contexts must be preloaded.
+ */
+function theme_panels_common_context_list($object) {
+  $titles = array();
+  $output = '';
+  $count = 1;
+  // First, make a list of arguments. Arguments are pretty simple.
+  if (!empty($object->arguments)) {
+    foreach ($object->arguments as $argument) {
+      $output .= '<tr>';
+      $output .= '<td><em>' . t('Argument @count', array('@count' => $count)) . '</em></td>';
+      $output .= '<td>' . check_plain($argument['identifier']) . '</td>';
+      $output .= '</tr>';
+      $titles[panels_argument_context_id($argument)] = $argument['identifier'];
+      $count++;
+    }
+  }
+  $count = 1;
+  // Then, make a nice list of contexts.
+  if (!empty($object->contexts)) {
+    foreach ($object->contexts as $context) {
+      $output .= '<tr>';
+      $output .= '<td><em>' . t('Context @count', array('@count' => $count)) . '</em></td>';
+      $output .= '<td>' . check_plain($context['identifier']) . '</td>';
+      $output .= '</tr>';
+      $titles[panels_context_context_id($context)] = $context['identifier'];
+      $count++;
+    }
+  }
+  // And relationships
+  if (!empty($object->relationships)) {
+    foreach ($object->relationships as $relationship) {
+      $output .= '<tr>';
+      $output .= '<td><em>' . t('From @title', array('@title' => $titles[$relationship['context']])) . '</em></td>';
+      $output .= '<td>' . check_plain($relationship['identifier']) . '</td>';
+      $output .= '</tr>';
+      $titles[panels_relationship_context_id($relationship)] = $relationship['identifier'];
+      $count++;
+    }
+  }
+  if ($output) {
+    return "<table><tbody>$output</tbody></table>\n";
+  }
+}
+
+/**
+ * Theme the form item for the context entry.
+ */
+function theme_panels_common_context_item_row($type, $form, $position, $count, $with_tr = TRUE) {
+  $output = '<td class="title">&nbsp;' . drupal_render($form['title']) . '</td>';
+
+  $arrows = '';
+  $type_info = panels_common_context_info($type);
+  if (!empty($type_info['sortable'])) {
+    $arrows = drupal_render($form['up']) .
+              drupal_render($form['down']) .
+              drupal_render($form['top']) .
+              drupal_render($form['bottom']);
+  }
+
+  $output .= '<td class="operation">' . drupal_render($form['settings']) .
+    $arrows . drupal_render($form['remove']) .
+  '</td>';
+  if ($with_tr) {
+    $output = '<tr id="' . $type . '-row-' . $position . '" class="' . $type . '-row ' . ($count % 2 ? 'even' : 'odd') . '">' . $output . '</tr>';
+  }
+  return $output;
+}
+
+/**
+ * Add the contexts form to panel page settings
+ */
+function theme_panels_common_context_item_form($form) {
+  $output = '';
+  $type = $form['#panels_context_type'];
+  $module = $form['#panels_context_module'];
+  $name = $form['#panel_name'];
+
+  $type_info = panels_common_context_info($type);
+
+  if (!empty($form[$type]) && empty($form['#only_buttons'])) {
+    $output .= '<table id="' . $type . '-table">';
+    $output .= '<thead>';
+    $output .= '<tr>';
+    $output .= '<th class="title">' . $type_info['title'] . '</th>';
+    $output .= '<th class="operation operation">' . t('Operation') . '</th>';
+    $output .= '</thead>';
+    $output .= '<tbody>';
+
+    $count = 0;
+    foreach (array_keys($form[$type]) as $id) {
+      if (!is_numeric($id)) {
+        continue;
+      }
+      $output .= theme('panels_common_context_item_row', $type, $form[$type][$id], $id, $count++);
+    }
+
+    $output .= '</tbody>';
+    $output .= '</table>';
+  }
+
+  if (!empty($form['buttons'])) {
+    // Display the add context item.
+    $row = array();
+    $row[] = array('data' => drupal_render($form['buttons'][$type]['item']), 'class' => 'title');
+    $row[] = array('data' => drupal_render($form['buttons'][$type]['add']), 'class' => 'add', 'width' => "60%");
+    $output .= '<div class="buttons">';
+    $output .= theme('table', array(), array($row), array('id' => $type . '-add-table'));
+    $output .= '</div>';
+  }
+  if (!empty($form['description'])) {
+    $output .= drupal_render($form['description']);
+  }
+
+  return $output;
+}
+
+// ---------------------------------------------------------------------------
+// Panels theming functions
+
+// @DND
+function theme_panels_dnd($content) {
+  $output = '<div class="panels-dnd" id="panels-dnd-main">' . $content . '</div>';
+  return $output;
+}
+
+// @DND
+function theme_panels_panel_dnd($content, $area, $label, $footer) {
+  return "<div class='panels-display' id='panel-pane-$area'>$footer<h2 class='label'>$label</h2>$content</div>";
+}
+
+// @DND
+function theme_panels_pane_dnd($block, $id, $label, $left_buttons = NULL, $buttons = NULL) {
+  if (!$block->title) {
+    $block->title = t('No title');
+  }
+  static $count = 0;
+  $output .= '<div class="grabber">';
+  if ($buttons) {
+    $output .= '<span class="buttons">' . $buttons . '</span>';
+  }
+  if ($left_buttons) {
+    $output .= '<span class="left_buttons">' . $left_buttons . '</span>';
+  }
+  $output .= '<span class="text">' . $label . '</span></div>';
+  $output .= '<div class="panel-pane-collapsible">';
+  $output .= theme('panels_pane_collapsible', $block);
+  $output .= '</div>';
+  return $output;
+}
+
+// @DND
+function theme_panels_pane_collapsible($block) {
+  $output .= '<h2 class="title">' . $block->title . '</h2>';
+  $output .= '<div class="content">' . filter_xss_admin($block->content) . '</div>';
+  return $output;
+}
+
+/**
+ * This is separate because it must be outside the <form> to work, and
+ * everything in the form theme is inside the form.
+ */
+// @DND
+function theme_panels_hidden() {
+  $close_text = t('Close Window');
+  $close_image = theme('image', panels_get_path('images/icon-delete.png'), t('Close window'), t('Close window'));
+  $throbber_image = theme('image', panels_get_path('images/throbber.gif'), t('Loading...'), t('Loading'));
+  $output = <<<EOF
+<div class="panels-hidden">\n
+  <div id="panels-modal">\n
+    <div class="panels-modal-content">\n
+       <div class="modal-header">\n
+         <a class="close" href="#">$close_text $close_image</a>\n
+         <span class="modal-title">&nbsp;</span>\n
+       </div>\n
+       <div class="modal-content">\n
+       </div>\n
+    </div>\n
+  </div>\n
+  <div id="panels-throbber">\n
+    <div class="panels-throbber-wrapper">
+      $throbber_image\n
+    </div>
+  </div>\n
+</div>\n
+EOF;
+
+  return $output;
+}
+
